1 55 56 package org.jboss.axis.components.image; 57 58 import org.jboss.axis.utils.Messages; 59 import sun.awt.image.codec.JPEGImageEncoderImpl; 60 61 import java.awt.*; 62 import java.awt.image.BufferedImage ; 63 import java.io.IOException ; 64 import java.io.InputStream ; 65 import java.io.OutputStream ; 66 67 72 public class JDK13IO extends Component implements ImageIO 73 { 74 82 public void saveImage(String mimeType, Image image, OutputStream os) 83 throws Exception 84 { 85 86 BufferedImage rendImage = null; 87 88 if (image instanceof BufferedImage ) 90 { 91 rendImage = (BufferedImage )image; 92 } 93 else 94 { 95 MediaTracker tracker = new MediaTracker(this); 96 tracker.addImage(image, 0); 97 tracker.waitForAll(); 98 rendImage = new BufferedImage (image.getWidth(null), image.getHeight(null), 1); 99 Graphics g = rendImage.createGraphics(); 100 g.drawImage(image, 0, 0, null); 101 } 102 103 if ("image/jpeg".equals(mimeType)) 105 { 106 JPEGImageEncoderImpl j = new JPEGImageEncoderImpl(os); 107 j.encode(rendImage); 108 } 109 else 110 { 111 throw new IOException (Messages.getMessage("jpegOnly", mimeType)); 112 } 113 } 115 121 public Image loadImage(InputStream in) throws Exception 122 { 123 if (in.available() <= 0) 124 { 125 return null; 126 } 127 else 128 { 129 byte[] bytes = new byte[in.available()]; 130 in.read(bytes); 131 return Toolkit.getDefaultToolkit().createImage(bytes); 132 } 133 } } 135 136 | Popular Tags |