1 18 package org.apache.batik.svggen; 19 20 import java.awt.Dimension ; 21 import java.awt.image.BufferedImage ; 22 import java.io.File ; 23 import java.io.FileOutputStream ; 24 import java.io.IOException ; 25 import java.io.OutputStream ; 26 27 import org.apache.batik.ext.awt.image.codec.ImageEncoder; 28 import org.apache.batik.ext.awt.image.codec.PNGImageEncoder; 29 30 42 public class ImageHandlerPNGEncoder extends AbstractImageHandlerEncoder { 43 50 public ImageHandlerPNGEncoder(String imageDir, String urlRoot) 51 throws SVGGraphics2DIOException { 52 super(imageDir, urlRoot); 53 } 54 55 59 public final String getSuffix(){ 60 return ".png"; 61 } 62 63 67 public final String getPrefix(){ 68 return "pngImage"; 69 } 70 71 75 public void encodeImage(BufferedImage buf, File imageFile) 76 throws SVGGraphics2DIOException { 77 try { 78 OutputStream os = new FileOutputStream (imageFile); 79 ImageEncoder encoder = new PNGImageEncoder(os, null); 80 encoder.encode(buf); 81 os.close(); 82 } catch (IOException e) { 83 throw new SVGGraphics2DIOException(ERR_WRITE+imageFile.getName()); 84 } 85 } 86 87 91 public BufferedImage buildBufferedImage(Dimension size){ 92 return new BufferedImage (size.width, size.height, 93 BufferedImage.TYPE_INT_ARGB); 94 } 95 } 96 | Popular Tags |