在android中将大图像加载到位图

use*_*971 3 android image

嗨我使用下面的代码从SD卡加载图像,它运行正常,

Bitmap picture=BitmapFactory.decodeFile("/sdcard...");
Run Code Online (Sandbox Code Playgroud)

要么

Bitmap picture= BitmapFactory.decodeByteArray(byte[]..);  
Run Code Online (Sandbox Code Playgroud)

byte[]数组包含使用sdcard从sdcard读取的字节FileInputstream,而不是null.以上两个代码都可以正常工作 问题是它们不适用于较大的图像,例如我的图像尺寸为1.8 mb.我的应用程序在解码图像时崩溃.用于大图像的任何方法都会失败.任何解决方案都可以解决问题.

Ara*_*ram 6

尝试创建可清除的位图.

   byte[] data = ...(read byte array from file)
   BitmapFactory.Options opt = new BitmapFactory.Options();
   opt.inPurgeable = true;
   Bitmap picture = BitmapFactory.decodeByteArray(data, 0, data.length, opt); 
Run Code Online (Sandbox Code Playgroud)