1 16 17 package org.apache.axis.components.image; 18 19 import javax.imageio.IIOImage ; 20 import javax.imageio.ImageWriter ; 21 import java.awt.*; 22 import java.awt.image.BufferedImage ; 23 import java.io.InputStream ; 24 import java.io.OutputStream ; 25 import java.util.Iterator ; 26 27 35 public class MerlinIO extends Component implements ImageIO { 36 43 public void saveImage(String mimeType, Image image, OutputStream os) 44 throws Exception { 45 ImageWriter writer = null; 46 Iterator iter = javax.imageio.ImageIO.getImageWritersByMIMEType(mimeType); 47 if (iter.hasNext()) { 48 writer = (ImageWriter ) iter.next(); 49 } 50 writer.setOutput(javax.imageio.ImageIO.createImageOutputStream(os)); 51 BufferedImage rendImage = null; 52 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 writer.write(new IIOImage (rendImage, null, null)); 63 writer.dispose(); 64 } 65 66 71 public Image loadImage(InputStream in) throws Exception { 72 return javax.imageio.ImageIO.read(in); 73 } 74 } 75 76 | Popular Tags |