1 16 17 package org.apache.axis.components.image; 18 19 import org.apache.axis.utils.Messages; 20 import org.apache.axis.utils.IOUtils; 21 import sun.awt.image.codec.JPEGImageEncoderImpl; 22 23 import java.awt.Component ; 24 import java.awt.Graphics ; 25 import java.awt.Image ; 26 import java.awt.MediaTracker ; 27 import java.awt.Toolkit ; 28 import java.awt.image.BufferedImage ; 29 import java.io.IOException ; 30 import java.io.InputStream ; 31 import java.io.OutputStream ; 32 33 38 public class JDK13IO extends Component implements ImageIO { 39 46 public void saveImage(String mimeType, Image image, OutputStream os) 47 throws Exception { 48 49 BufferedImage rendImage = null; 50 51 if (image instanceof BufferedImage ) { 53 rendImage = (BufferedImage ) image; 54 } else { 55 MediaTracker tracker = new MediaTracker (this); 56 tracker.addImage(image, 0); 57 tracker.waitForAll(); 58 rendImage = new BufferedImage (image.getWidth(null), image.getHeight(null), 1); 59 Graphics g = rendImage.createGraphics(); 60 g.drawImage(image, 0, 0, null); 61 } 62 63 if ("image/jpeg".equals(mimeType)) { 65 JPEGImageEncoderImpl j = new JPEGImageEncoderImpl(os); 66 j.encode(rendImage); 67 } 68 else { 69 throw new IOException (Messages.getMessage("jpegOnly", mimeType)); 70 } 71 } 73 78 public Image loadImage(InputStream in) throws Exception { 79 if (in.available() <= 0) { 80 return null; 81 } 82 else { 83 byte[] bytes = new byte[in.available()]; 84 IOUtils.readFully(in,bytes); 85 return Toolkit.getDefaultToolkit().createImage(bytes); 86 } 87 } } 89 90 | Popular Tags |