Blackberry - OutOfMemory when handling big images
开发者_运维百科Im developing an app that shows big images.. There are a lot of images which size is around 700x8100.. I can create an object of type EncodedImage, without throwing an exception, but when I try to execute getBitmap I receive an OutOfMemory error. This is the line that occurs the exception:
Bitmap imgBtm = encodedImagePng.getBitmap();
Is there any kind of resolution size limit?
Does anyone already had to handle big images?
Any help will be very useful..
Tks
You have to resize the encoded Image before using the getBitmap() function. First construct your EncodedImage and then rescale it using the following:
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;
}
And then after resizing get the Bitmap from it
You can't read images that are so large into device memory. There are built-in methods to decode an image while scaling it down, which will avoid loading the original image into memory. Try EncodedImage.scaleImage32 to set a more reasonable dimension before getting a bitmap.
精彩评论