2017-03-02 106 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; 
}