1 34 35 package org.krysalis.jcharts.encoders; 36 37 38 import com.sun.image.codec.jpeg.JPEGCodec; 39 import com.sun.image.codec.jpeg.JPEGEncodeParam; 40 import com.sun.image.codec.jpeg.JPEGImageEncoder; 41 import org.krysalis.jcharts.Chart; 42 import org.krysalis.jcharts.chartData.ChartDataException; 43 import org.krysalis.jcharts.properties.PropertyException; 44 45 import java.awt.image.BufferedImage ; 46 import java.awt.image.BufferedImageOp ; 47 import java.awt.image.ConvolveOp ; 48 import java.awt.image.Kernel ; 49 import java.io.IOException ; 50 import java.io.OutputStream ; 51 52 53 59 public class JPEGEncoder13 60 { 61 62 66 private JPEGEncoder13() throws Exception 67 { 68 throw new Exception ( "No need to create an instance of this class!" ); 69 } 70 71 72 82 public static void encode( Chart chart, 83 float quality, 84 OutputStream outputStream ) throws ChartDataException, PropertyException, IOException 85 { 86 BufferedImage bufferedImage = BinaryEncoderUtil.render( chart ); 87 88 float[] sharpKernel = {0.0f, -1.0f, 0.0f, 89 -1.0f, 5.0f, -1.0f, 90 0.0f, -1.0f, 0.0f}; 91 92 BufferedImageOp sharpen = new ConvolveOp ( new Kernel ( 3, 3, sharpKernel ), ConvolveOp.EDGE_NO_OP, null ); 93 BufferedImage sharp = sharpen.filter( bufferedImage, null ); 94 95 JPEGEncodeParam jpegParam = JPEGCodec.getDefaultJPEGEncodeParam( sharp ); 97 jpegParam.setQuality( quality, false ); 98 99 JPEGImageEncoder jpeg = JPEGCodec.createJPEGEncoder( outputStream, jpegParam ); 100 101 jpeg.encode( bufferedImage ); 103 104 } 105 } 106 107 108 109 | Popular Tags |