Scaling BufferedImage?

Hello,

Could anyone advice if there any java tools to created a scaled down version of an image contained with a BufferedImage.

I would like to create a thumbnail image, of the orginal and then write this thumbnail to a new file.

Thank you
AntoniRyszardAsked:
Who is Participating?
 
rrzCommented:
Try something like this.

     public static BufferedImage scale(BufferedImage bi){
         Image img = bi.getScaledInstance(100,-1,Image.SCALE_SMOOTH);
         int w = img.getWidth(null);
         int h = img.getHeight(null);
         BufferedImage scaled = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);            
         Graphics2D g = scaled.createGraphics();
         g.drawImage(img,0,0,null);
         if(g != null) g.dispose();
         return scaled;
     }
0
 
mrigankCommented:
0
 
AntoniRyszardAuthor Commented:
Using the code in this example, do you think the thumbnail images would be all the same size?

Thanks
0
 
AntoniRyszardAuthor Commented:
Even if the orginal images were different sizes?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.