At 03:21 PM 6/8/99 -0300, you wrote:
>I want to save an image that appears in an JLabel component to a gif/jpeg
>file. Does anyone know a way to implement this?
>

I've used JPEGImageDecoder/Encoder (part of the com.sun.image.codec.jpeg.*
that ships with 1.2) like this:

Read JPEG (spacing, linewrap courtesy of cut&paste):

 ImageIcon thumbnail = null;
 File f = null;
 Image img = null;
 BufferedImage bufout = null;
 ...
 try {
  JPEGImageDecoder codedec = JPEGCodec.createJPEGDecoder(new
BufferedInputStream(
                              new FileInputStream(f.getPath())));
  thumbnail = new
ImageIcon(codedec.decodeAsBufferedImage().getScaledInstance(150, -1,
Image.SCALE_DEFAULT));
 }
 catch (Throwable fnfe) {
        System.out.println("JPEG read failed, error:"+fnfe);
 }

Write JPEGs I've used something like:
   ...
 int iw = thumbnail.getIconWidth();
 int ih = thumbnail.getIconHeight();
 bufout = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);
 img = thumbnail.getImage();
 Graphics2D big = bufout.createGraphics();
 big.drawImage(img,0,0,this);
 JPEGImageEncoder codeenc = JPEGCodec.createJPEGEncoder(new
BufferedOutputStream(
                             new FileInputStream(f.getPath())));
 codeenc.encode(bufout);

Probably are other ways.... Hope this helps.
Chris


=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 2D Home Page: http://java.sun.com/products/java-media/2D/

Reply via email to