• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

image thumbnail question

 
Ranch Hand
Posts: 49
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22697
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
It was the best of times. It was the worst of times. It was a tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic