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 com.sun.image.codec.jpeg.JPEGCodec; 28 import com.sun.image.codec.jpeg.JPEGEncodeParam; 29 import com.sun.image.codec.jpeg.JPEGImageEncoder; 30 31 43 public class ImageHandlerJPEGEncoder extends AbstractImageHandlerEncoder { 44 51 public ImageHandlerJPEGEncoder(String imageDir, String urlRoot) 52 throws SVGGraphics2DIOException { 53 super(imageDir, urlRoot); 54 } 55 56 60 public final String getSuffix() { 61 return ".jpg"; 62 } 63 64 68 public final String getPrefix() { 69 return "jpegImage"; 70 } 71 72 76 public void encodeImage(BufferedImage buf, File imageFile) 77 throws SVGGraphics2DIOException { 78 try{ 79 OutputStream os = new FileOutputStream (imageFile); 80 JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os); 81 JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(buf); 82 param.setQuality(1, false); 83 encoder.encode(buf, param); 84 os.flush(); 85 os.close(); 86 } catch(IOException e) { 87 throw new SVGGraphics2DIOException(ERR_WRITE+imageFile.getName()); 88 } 89 } 90 91 95 public BufferedImage buildBufferedImage(Dimension size) { 96 return new BufferedImage (size.width, size.height, 97 BufferedImage.TYPE_INT_RGB); 98 } 99 } 100 | Popular Tags |