Re: getScaledInstance for BufferedImage.

From: Roedy Green (look-on_at_mindprod.com.invalid)
Date: 05/13/04


Date: Thu, 13 May 2004 07:22:39 GMT

On Thu, 13 May 2004 06:56:23 GMT, Roedy Green
<look-on@mindprod.com.invalid> wrote or quoted :

>getScaledInstance produces an Image out of my BufferedImage.
>It does not produced a BufferedImage I can simply cast.
>
>
>What is the best to way to either convert it back to a BufferedImage
>or to get myself a scaled BufferedImage?

After some horsing around here is what appears to work, but my choice
of type TYPE_INT_BGR was arbitrary. It seems goofy to change from
JPEG to bit map to convert back to JPEG map gain.

 // magnify which has side effect of turning back to plain Image.
Image magnifiedImage
  = image.getScaledInstance( magnifiedImageWidth,
                                          magnifiedImageHeight,
                                          BufferedImage.SCALE_SMOOTH);

 // convert back to BufferedImage
BufferedImage bufferedImage = new BufferedImage (

magnifiedImageWidth,

magnifiedImageHeight,

BufferedImage.TYPE_INT_BGR);
 bufferedImage.createGraphics().drawImage(
                        magnifiedImage, 0, 0, this /* observer */ );

// write out the BufferedImage as a JPEG
ImageIO.write( bufferedImage,
                        "JPEG" /* format desired */ ,
                         file );

.

-- 
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming. 
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.


Relevant Pages

  • Re: getScaledInstance for BufferedImage.
    ... >>getScaledInstance produces an Image out of my BufferedImage. ... >>It does not produced a BufferedImage I can simply cast. ... > JPEG to bit map to convert back to JPEG map gain. ... > magnifiedImageWidth, ...
    (comp.lang.java.gui)
  • Re: Image manipulation in applications
    ... Saving a BufferedImage as a JPEG ... > I'm doing some image manipulation in an applet using the example code on> this page: ... > However, I really want an application rather than an applet, I just> can't figure out how to do the image loading and manipulation when it's> not from inside an applet. ...
    (comp.lang.java)
  • image to jpg
    ... Saving a BufferedImage as a JPEG ... > The JPEG is saved as CMYK but I need RGB. ... JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam; ...
    (comp.lang.java)
  • Re: Farbtiefe und dpi mit BufferedImage
    ... Du kannst ein BufferedImage als JPEG speichern, ... BufferedImage laden, aber bei "JPEG als BufferedImage gespeichert" ... Möchtest Du eine JPEG-Datei auf Farbtiefe ...
    (de.comp.lang.java)