Scaling BufferedImage?

Posted on 2006-04-12
Last Modified: 2013-11-22

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
Question by:AntoniRyszard
    LVL 5

    Expert Comment


    Author Comment

    Using the code in this example, do you think the thumbnail images would be all the same size?


    Author Comment

    Even if the orginal images were different sizes?
    LVL 27

    Accepted Solution

    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();
             if(g != null) g.dispose();
             return scaled;

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    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…
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now