1 18 package org.apache.batik.svggen; 19 20 import java.awt.image.BufferedImage ; 21 import java.io.IOException ; 22 import java.io.OutputStream ; 23 24 import com.sun.image.codec.jpeg.JPEGCodec; 25 import com.sun.image.codec.jpeg.JPEGEncodeParam; 26 import com.sun.image.codec.jpeg.JPEGImageEncoder; 27 28 34 public class CachedImageHandlerJPEGEncoder extends DefaultCachedImageHandler { 35 public static final String CACHED_JPEG_PREFIX = "jpegImage"; 36 public static final String CACHED_JPEG_SUFFIX = ".jpg"; 37 38 protected String refPrefix = ""; 39 40 47 public CachedImageHandlerJPEGEncoder(String imageDir, String urlRoot) 48 throws SVGGraphics2DIOException { 49 refPrefix = urlRoot + "/"; 50 setImageCacher(new ImageCacher.External(imageDir, 51 CACHED_JPEG_PREFIX, 52 CACHED_JPEG_SUFFIX)); 53 } 54 55 58 public void encodeImage(BufferedImage buf, OutputStream os) 59 throws IOException { 60 JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os); 61 JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(buf); 62 param.setQuality(1, false); 63 encoder.encode(buf, param); 64 } 65 66 public int getBufferedImageType(){ 67 return BufferedImage.TYPE_INT_RGB; 68 } 69 70 public String getRefPrefix(){ 71 return refPrefix; 72 } 73 } 74 | Popular Tags |