Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 09:37, 27 November 2007.

How to create thumbnail in Java ME

From Forum Nokia Wiki


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 S60 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.

Related Discussions
Thread Thread Starter Forum Replies Last Post
Java/SMS compatibility SundariDevi Mobile Java General 1 2002-09-23 08:03
Tomcat and JVM configuration problem arunshah Mobile Java General 1 2007-02-05 19:48
Unable to create java directory bpettorelli Mobile Java Tools & SDKs 1 2003-07-03 11:25
"cannot create class" akshay0912 Mobile Java General 8 2008-07-10 08:23
KNI in J2ME for interation with C++ API samir01m11 Mobile Java General 9 2006-11-03 00:19
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtopicQUqfnTopicZjavaQ
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX