我建立一個應用程序上,當我試圖在ImageView的顯示圖像等我處理超大相似圖片的10000X5000像素 .The應用程序崩潰。 我無法去位圖採樣,因爲我無法更改圖像的大小。處理大量圖像
一個簡單的工作是選擇10000X5000像素的圖像並將其顯示在ImageView中。
目前,我正在爲此使用簡單的代碼,並且應用程序正在崩潰。
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
// Get the cursor
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
// Move to first row
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
imgDecodableString = cursor.getString(columnIndex);
cursor.close();
ImageView imgView = (ImageView) findViewById(R.id.imgView);
// Set the Image in ImageView after decoding the String
imgView.setImageBitmap(BitmapFactory
.decodeFile(imgDecodableString));
唯一的例外是內存不足
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.star.largeiamgesdemo,
PID: 21155 java.lang.OutOfMemoryError: Failed to allocate a 200000012 byte allocation with 4194208 free bytes and 123MB until OOM
像MemoryMapFile
東西可以做的伎倆,但它是文件FileChannel
更新未得到圖像什麼
我不能在顯示原因時縮小圖像,因爲我必須對其進行編輯(即用戶可以修改ITE東西在圖像上,或者作爲水印地方其他圖像對他們)
感謝
降低圖像分辨率和尺寸 –
**我無法去位圖採樣,因爲我無法更改圖像的大小。您需要縮小圖像。圖像的格式是什麼?是.png,.jpeg還是webp。 – Raghunandan
正如IntelliJ Amiya所說,但首先嚐試設置'useLargeHeap = true;',這不是推薦的方法,但它有時可能有用。 – Stanojkovic