2016-12-14 41 views
0

試圖從庫獲得的圖像,我的照片URI:content://com.android.providers.media.documents/document/image%3A15672BitmapFactory.decodeStream返回空與bmOptions

當我不使用bmOptions(BitmapFactory.decodeStream(inStream))我得到位圖圖像成功地,但是當我添加bmOptions BitmapFactory.decodeStream(inStream,null,bmOptions))我得到null位圖,無法找出做錯了。

private void setPic(Uri photoUri) { 

     InputStream inStream = null; 
     try { 
      inStream = getContentResolver().openInputStream(photoUri); 
     } catch (FileNotFoundException e) { 
      e.printStackTrace(); 
     } 
     BitmapFactory.Options bmOptions = new BitmapFactory.Options(); 
     bmOptions.inJustDecodeBounds = true; 

     Log.i("response", "INPUT STREAM| Bitmap : "+ BitmapFactory.decodeStream(inStream,null,bmOptions)); 

    } 

回答

1

如果使用bmOptions.inJustDecodeBounds = true;,它可以轉化爲人類的語言爲don't load the bitmap, just resolve it's size and some other metadata這是預期的行爲,通常是用於瞭解裝貨前Bitmap大小它以內存來防止OOM異常,並加載位圖預縮小。

+0

恰到好處:) –

相關問題