×
Namespaces

Variants
Actions

How to create thumbnail in Java ME

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: wang_shui (19 Mar 2007)
Last edited: hamishwillee (30 Jul 2013)

Create a thumbnail image from a large image or scale an image in Java ME

private Image createThumbnail(Image image) {
int sourceWidth = image.getWidth();
int sourceHeight = image.getHeight();
 
int thumbWidth = 64;
int thumbHeight = -1;
 
if (thumbHeight == -1)
thumbHeight = thumbWidth * sourceHeight / sourceWidth;
 
Image thumb = Image.createImage(thumbWidth, thumbHeight);
Graphics g = thumb.getGraphics();
 
for (int y = 0; y < thumbHeight; y++) {
for (int x = 0; x < thumbWidth; x++) {
g.setClip(x, y, 1, 1);
int dx = x * sourceWidth / thumbWidth;
int dy = y * sourceHeight / thumbHeight;
g.drawImage(image, x - dx, y - dy,
Graphics.LEFT | Graphics.TOP);
}
}
 
Image immutableThumb = Image.createImage(thumb);
 
return immutableThumb;
}

You may also use http://www.java-tips.org/java-me-tips/midp/how-to-implement-oom-in-and-oom-out.html

If you are using Symbian devices, you can load the thumbnails generated automatically by the Gallery application. They are located in the "_PAlbTN" sub-folders of Image.

For more details on this, check Thumbnail path for 3rd edition devices.

This page was last modified on 30 July 2013, at 11:06.
62 page views in the last 30 days.
×