我正在开发一个显示大图像的应用程序。有很多图片的大小都在700x8100左右。我可以创建一个EncodedImage类型的对象,而不会抛出异常,但是当我尝试执行getBitmap时,我收到一个OutOfMemory错误。这是出现异常的行:
Bitmap imgBtm = encodedImagePng.getBitmap();
是否有分辨率大小限制?
有人已经处理过大图片了吗?
任何帮助都会非常有用。
谢谢
您必须在使用getBitmap()函数之前调整编码图像的大小。首先构造EncodedImage,然后使用以下命令重新缩放它:
private static EncodedImage rescaleEncodedImage (EncodedImage image, int width, int height) {
EncodedImage result = null;
try {
int currentWidthFixed32 = Fixed32.toFP(image.getWidth());
int currentHeightFixed32 = Fixed32.toFP(image.getHeight());
int requiredWidthFixed32 = Fixed32.toFP(width);
int requiredHeightFixed32 = Fixed32.toFP(height);
int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32);
int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32);
result = image.scaleImage32(scaleXFixed32, scaleYFixed32);
}
catch (Exception ex) {
}
return result;
}
然后在调整大小后从中获取位图
您无法将如此大的图像读取到设备内存中。有一些内置的方法可以在缩小图像时解码图像,这将避免将原始图像加载到内存中。EncodedImage试试。scaleImage32在获得位图之前设置一个更合理的尺寸