2017-03-02 109 views
-1

虽然在协调加载从本地存储路径图像布局和应用栏布局变得生涩而滚动生涩滚动,而从本地存储加载图像

我用了myImageview.setImageURI(MYURI);,但不能正常工作

+0

如果相当重,这并不奇怪,因为你在UI线程中加载它。你可以尝试使用一些库,例如毕加索来加载它。 –

+0

因为我使用图书馆我使用毕加索图书馆,但当我不使用任何图书馆时我该怎么办? –

+0

将图像加载到后台线程中的位图,然后将Bitmap设置为ImageView –

回答

0

我的问题解决了作为我使用毕加索采用波纹管代码

Picasso.with(context).load(YOUR_IMAGE_URI).placeholder(R.drawable.profile_img).error(R.drawable.profile_imgd).resize(250,250).centerCrop().into(myImageview); 

我曾试图然而,我曾尝试波纹管代码,但我认为这可能是有益的

public static Bitmap decodeFile(File f, int reqWidth, int reqHeight) { 
    Bitmap b = null; 

    //Decode image size 
    BitmapFactory.Options o = new BitmapFactory.Options(); 
    o.inJustDecodeBounds = true; 

    FileInputStream fis = null; 
    try { 
     fis = new FileInputStream(f); 
     BitmapFactory.decodeStream(fis, null, o); 
     fis.close(); 

    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

    //Decode with inSampleSize 
    BitmapFactory.Options o2 = new BitmapFactory.Options(); 
    o2.inSampleSize = calculateInSampleSize(o2,reqWidth, reqHeight); 

    try { 
     fis = new FileInputStream(f); 
     b = BitmapFactory.decodeStream(fis, null, o2); 
     fis.close(); 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    return b; 

} 

public static int calculateInSampleSize(
     BitmapFactory.Options options, int reqWidth, int reqHeight) { 
    // Raw height and width of image 
    final int height = options.outHeight; 
    final int width = options.outWidth; 
    int inSampleSize = 1; 

    if (height > reqHeight || width > reqWidth) { 

     final int halfHeight = height/2; 
     final int halfWidth = width/2; 

     // Calculate the largest inSampleSize value that is a power of 2 and keeps both 
     // height and width larger than the requested height and width. 
     while ((halfHeight/inSampleSize) > reqHeight 
       && (halfWidth/inSampleSize) > reqWidth) { 
      inSampleSize *= 2; 
     } 
    } 

    return inSampleSize; 
}