• Post Reply Bookmark Topic Watch Topic
  • New Topic

image thumbnail question

 
krillian konstatos
Ranch Hand
Posts: 49
Java Netbeans IDE PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, forumists!

I have a problem regarding the creation of thumbnails from images selected from a filechooser.
I draw theese thumbnails on a JLabel object with the width and height set to 133 x 98. I am not
that sure if i am using the standard approach to do this i have the code as posted below.



I am creating the icon on a variable referred to a BufferedImage and attach this to
my JLabel object. It is now that i am uncertain of if i am doing things in the right order. I want to
paint the icon in question on my JLabel object using the graphics and dimension that are
derrived from the BufferedImage object? Is this the correct way or is there something that
i have missed out totally or should i do things much differently? All feedback is greatly
appreciated since i am struggling very hard with an image organizer application.

Very kind regards,
Krill!
 
Darryl Burke
Bartender
Posts: 5153
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only thing I see that I don't like is constructing an ImageIcon only to obtain its Image. I would read the image using ImageIO#read(...). And using getScaledInstance(...) might save you some lines of code.
 
Rob Spoor
Sheriff
Posts: 20819
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, getScaledInstance is not recommended. Read http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html for more info.
 
Darryl Burke
Bartender
Posts: 5153
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two quotes from that page:
When downscaling an image, the choice is slightly more complex. The same advice regarding RenderingHints given for upscaling is generally applicable to downscaling as well. However, be aware that if you try to downscale an image by a factor of more than two (i.e., the scaled instance is less than half the size of the original), and you are using the BILINEAR or BICUBIC hint, the quality of the scaled instance may not be as smooth as you might like. If you are familiar with the quality of the old Image.SCALE_AREA_AVERAGING (or Image.SCALE_SMOOTH) hint, then you may be especially dismayed.


In JDK 7 we do plan to provide a more optimized implementation of BufferedImage.getScaledInstance()


For one-time generation of thumbnails, I would at least give getScaledInstance a try and stick with it if the results proved to be satisfactory.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!