FileDocCategorySizeDatePackage
JDK13IO.javaAPI DocApache Axis 1.42855Sat Apr 22 18:57:28 BST 2006org.apache.axis.components.image

JDK13IO

public class JDK13IO extends Component implements ImageIO
JDK1.3 based Image I/O
author
Russell Butek

Fields Summary
Constructors Summary
Methods Summary
public java.awt.ImageloadImage(java.io.InputStream in)
Load an Image.

param
in the stream to load the image
return
the Image

        if (in.available() <= 0) {
            return null;
        }
        else {
            byte[] bytes = new byte[in.available()];
            IOUtils.readFully(in,bytes);
            return Toolkit.getDefaultToolkit().createImage(bytes);
        }
    
public voidsaveImage(java.lang.String mimeType, java.awt.Image image, java.io.OutputStream os)
Save an image.

param
mimeType the mime-type of the format to save the image
param
image the image to save
param
os the stream to write to
exception
Exception if an error prevents image encoding


        BufferedImage rendImage = null;

        // Create a BufferedImage
        if (image instanceof BufferedImage) {
            rendImage = (BufferedImage) image;
        } else {
            MediaTracker tracker = new MediaTracker(this);
            tracker.addImage(image, 0);
            tracker.waitForAll();
            rendImage = new BufferedImage(image.getWidth(null), image.getHeight(null), 1);
            Graphics g = rendImage.createGraphics();
            g.drawImage(image, 0, 0, null);
        }

        // Write the image to the output stream
        if ("image/jpeg".equals(mimeType)) {
            JPEGImageEncoderImpl j = new JPEGImageEncoderImpl(os);
            j.encode(rendImage);
        }
        else {
            throw new IOException(Messages.getMessage("jpegOnly", mimeType));
        }