1 42 43 package org.jfree.chart.encoders; 44 45 import com.keypoint.PngEncoder; 46 47 import java.awt.image.BufferedImage ; 48 import java.io.IOException ; 49 import java.io.OutputStream ; 50 51 58 public class KeypointPNGEncoderAdapter implements ImageEncoder { 59 private int quality = 9; 60 private boolean encodingAlpha = false; 61 62 69 public float getQuality() { 70 return this.quality; 71 } 72 73 81 public void setQuality(float quality) { 82 this.quality = (int) quality; 83 } 84 85 90 public boolean isEncodingAlpha() { 91 return this.encodingAlpha; 92 } 93 94 100 public void setEncodingAlpha(boolean encodingAlpha) { 101 this.encodingAlpha = encodingAlpha; 102 } 103 104 111 public byte[] encode(BufferedImage bufferedImage) throws IOException { 112 if (bufferedImage == null) { 113 throw new IllegalArgumentException ("Null 'image' argument."); 114 } 115 PngEncoder encoder = new PngEncoder(bufferedImage, this.encodingAlpha, 116 0, this.quality); 117 return encoder.pngEncode(); 118 } 119 120 128 public void encode(BufferedImage bufferedImage, OutputStream outputStream) 129 throws IOException { 130 if (bufferedImage == null) { 131 throw new IllegalArgumentException ("Null 'image' argument."); 132 } 133 if (outputStream == null) { 134 throw new IllegalArgumentException ("Null 'outputStream' argument."); 135 } 136 PngEncoder encoder = new PngEncoder(bufferedImage, this.encodingAlpha, 137 0, this.quality); 138 outputStream.write(encoder.pngEncode()); 139 } 140 141 } 142 | Popular Tags |