2

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;
Spikatrix
  • 20,225
  • 7
  • 37
  • 83
Bebeto
  • 49
  • 9

2 Answers2

0

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.

michael aubert
  • 6,836
  • 1
  • 16
  • 32
0

Many cameras save a thumbnail in the exif data of the picture, so cameras can show a thumbnail quickly rather than needing to scale down a full-size image.

This technique is theoretically also possible with JavaME, and you can find many guides on how to do it if you google for it: http://www.google.com/#q=j2me+exif+thumbnail

I must admit though, that I never succeeded in doing it some time back when I tried it, I think it was on a Sony Ericsson Aino. One problem is that (as usual, almost no matter what topic you look at) different companies do it different ways. This naturally makes it rather difficult to implement universal "works-everywhere code".

mr_lou
  • 1,910
  • 2
  • 14
  • 26