1 16 17 package org.apache.axis2.attachments; 18 19 20 import sun.awt.image.codec.JPEGImageEncoderImpl; 21 22 import java.awt.*; 23 import java.awt.image.BufferedImage ; 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.io.OutputStream ; 27 28 33 public class JDK13IO extends Component implements ImageIO { 34 41 public void saveImage(String mimeType, Image image, OutputStream os) 42 throws Exception { 43 44 BufferedImage rendImage = null; 45 46 if (image instanceof BufferedImage ) { 48 rendImage = (BufferedImage ) image; 49 } else { 50 MediaTracker tracker = new MediaTracker(this); 51 tracker.addImage(image, 0); 52 tracker.waitForAll(); 53 rendImage = new BufferedImage (image.getWidth(null), image.getHeight(null), 1); 54 Graphics g = rendImage.createGraphics(); 55 g.drawImage(image, 0, 0, null); 56 } 57 58 if ("image/jpeg".equals(mimeType)) { 60 JPEGImageEncoderImpl j = new JPEGImageEncoderImpl(os); 61 j.encode(rendImage); 62 } 63 else { 64 throw new IOException ("Supports Jpeg Only"); 65 } 66 } 68 73 public Image loadImage(InputStream in) throws Exception { 74 if (in.available() <= 0) { 75 return null; 76 } 77 else { 78 byte[] bytes = new byte[in.available()]; 79 org.apache.axis2.attachments.IOUtils.readFully(in,bytes); 80 return Toolkit.getDefaultToolkit().createImage(bytes); 81 } 82 } } 84 85 | Popular Tags |