我建立一个应用程序上,当我试图在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