通過以下this link,我編寫了以下代碼以顯示sdcard中的大圖像位圖。大型位圖無法從Android中的SD卡高效加載
try {
InputStream lStreamToImage = context.getContentResolver().openInputStream(Uri.parse(imagePath));
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(lStreamToImage, null, options);
options.inSampleSize = 8; //Decrease the size of decoded image
options.inPreferredConfig = Bitmap.Config.ARGB_4444;
options.inJustDecodeBounds = false;
bitmap = BitmapFactory.decodeStream(lStreamToImage, null, options);
} catch(Exception e){}
image.setImageBitmap(bitmap);
但它沒有返回位圖(我的意思是返回null)。在logcat的是露出反覆
08-02 17:21:04.389: D/skia(19359): --- SkImageDecoder::Factory returned null
下面的消息,如果我會評論的options.inJustDecodeBounds線並重新運行它,它工作正常,但速度緩慢。上面提供的開發人員指南鏈接I說,使用inJustDecodeBounds可以有效地加載位圖。
請告訴我我做錯了什麼。
親愛的DeeV文檔說如果設置爲true,它將返回null,但它會預處理它。但是,如果你想獲得預處理的位圖,然後將其設置爲false並重新獲得它。我在上面做了什麼。請參閱上面給出的文檔鏈接,它也做同樣的事情。 – 2012-08-02 12:27:34
我認爲他們說錯了「處理它」。它「處理」圖像的意義在於,它會給你圖像的大小而不完全解碼圖像。注意,我似乎還記得一個月前有人試圖重複使用同一個Options對象的問題,並且它一直在崩潰。最後,他必須創造一個新的。 – DeeV 2012-08-02 12:40:13
這有史以來的工作?我正在查看你的代碼,並試圖找出哪裏出了問題。除了重新使用BitmapFactory.Options對象(由於某些原因導致問題)之外,我沒有看到提供的段。 – DeeV 2012-08-05 14:10:00