我不斷嘗試在我的Android應用程序中解碼攝像頭圖像時發生OutOfMemory異常。處理這個問題有很多問題,但是我的情況特別奇怪,因爲即使只是試圖通過options.inJustDecodeBounds=true
獲得邊界,我也會得到例外。OutOfMemory使用inJustDecodeBounds = true解碼圖像
下面是開始對相機的代碼:
protected void takePicture() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File image = new File(IMAGE_PATH, "camera.jpg");
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
startActivityForResult(takePictureIntent, 0);
}
下面是觸發異常的代碼:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
String rawImageName = new String(IMAGE_PATH + "/camera.jpg");
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(rawImageName); // The exception is thrown here
.
.
.
}
}
我試圖用一個非常高的採樣率圖像進行解碼,但我仍然得到相同的例外:
options.inSampleSize = 20;
options.inJustDecodeBounds = false;
options.inPreferredConfig = Bitmap.Config.RGB_565;
Bitmap photo = BitmapFactory.decodeFile(rawImageName); // Again the exception
除此之外,應用程序似乎運行co正確,並有足夠的空閒內存。我可以正確打開圖庫應用程序中的圖像。將圖像移動到不同的目錄並沒有幫助。任何想法可能會導致它?使用inJustDecodeBounds = true
進行解碼時可能會導致異常情況?
告訴我們你的堆棧跟蹤。 – Archer
我想你應該看看這個鏈接:http://developer.android.com/training/displaying-bitmaps/load-bitmap.html – Houcine
嗯,這恰好是一個愚蠢的複製粘貼錯誤。該問題是否應該刪除?它對別人有什麼價值嗎? – FireAphis