这是我的代码:
File file = new File(Jpeg文件路径大小为700kb);
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(file));
}
catch (Exception e) {
// TODO: handle exception
}
bitmap =BitmapFactory.decodeStream(in);
bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
请帮助我在这个复制行中遇到错误,我想制作其 ARGB_8888 图像。需要帮助:(
最佳答案
您需要减少内存使用量。
在您的代码中,您首先将流解码为一个位图,然后复制它,这意味着您创建两个大位图对象。
不需要解码然后复制,可以尝试
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888
// You can try value larger than 1
options.inSampleSize = 2 // If set to a value > 1, requests the decoder to subsample the original image, returning a smaller image to save memory.
// Decode bitmap
bitmap = BitmapFactory.decodeStream(in, null, options)
在本例中,仅创建了一个位图。并且将 inSampleSize 设置为较大的值以减小加载的位图大小。
关于android - 将图像转换为 ARGB_8888 时出现错误 :Bitmap size Exceed VM budget,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9650175/