Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

How to create thumbnail in Java ME

From 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 08:06.
73 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×