This code is use for displaying an image in a Thumbnail format. And i got a problem (Out of Memory) when an image contain a dimension of 1600 x 1200 up. I'm using Series 40 and Series 60 J2ME Phones.
Kindly help me of my problem, Thanks.
Here is My code:
int sourceWidth = image.getWidth();
int sourceHeight = image.getHeight();
int thumbWidth = width;
int thumbHeight = height;
if (thumbHeight == -1)
thumbHeight = thumbWidth * sourceHeight / sourceWidth;
Image thumb = Image.createImage(thumbWidth, thumbHeight);
Graphics graph = thumb.getGraphics();
for (int y = 0; y < thumbHeight; y++) {
for (int x = 0; x < thumbWidth; x++) {
graph.setClip(x, y, 1, 1);
int dx = x * sourceWidth / thumbWidth;
int dy = y * sourceHeight / thumbHeight;
graph.drawImage(image, x - dx, y - dy, Graphics.TOP | Graphics.LEFT);
}
}
Image immutableThumb = Image.createImage(thumb);
return immutableThumb;
Can you avoid loading the whole image at once?
Can you split the image in four 800x600 images and create four 320x240 mini thumbnails to display next to each others?
If 4 still doesn't work, try 16.
Just be ready for any call to Image.createImage() to trigger a Garbage Collection pause.