1 28 package net.sf.jasperreports.engine.util; 29 30 import java.awt.Graphics ; 31 import java.awt.Image ; 32 import java.awt.image.BufferedImage ; 33 34 import net.sf.jasperreports.engine.JRException; 35 import net.sf.jasperreports.engine.JRRenderable; 36 37 38 42 public abstract class JRAbstractImageEncoder implements JRImageEncoder 43 { 44 45 46 49 public byte[] encode(Image image, byte imageType) throws JRException 50 { 51 BufferedImage bi = null; 52 53 if (image instanceof BufferedImage ) 54 { 55 bi = (BufferedImage )image; 56 } 57 else 58 { 59 bi = 60 new BufferedImage ( 61 image.getWidth(null), 62 image.getHeight(null), 63 (imageType == JRRenderable.IMAGE_TYPE_GIF || imageType == JRRenderable.IMAGE_TYPE_PNG) 66 ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB 67 ); 68 69 Graphics g = bi.createGraphics(); 70 g.drawImage(image, 0, 0, null); 71 g.dispose(); 72 } 73 74 return encode(bi, imageType); 75 } 76 77 78 81 public abstract byte[] encode(BufferedImage bi, byte imageType) throws JRException; 82 83 84 } 85 | Popular Tags |