[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Scaling BufferedImage?

Posted on 2006-04-12
4
Medium Priority
?
914 Views
Last Modified: 2013-11-22
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
0
Comment
Question by:AntoniRyszard
  • 2
4 Comments
 
LVL 5

Expert Comment

by:mrigank
ID: 16440550
0
 

Author Comment

by:AntoniRyszard
ID: 16440832
Using the code in this example, do you think the thumbnail images would be all the same size?

Thanks
0
 

Author Comment

by:AntoniRyszard
ID: 16440844
Even if the orginal images were different sizes?
0
 
LVL 28

Accepted Solution

by:
rrz earned 160 total points
ID: 16441905
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month17 days, 16 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question