1 42 43 package org.jfree.chart.encoders; 44 45 import java.awt.image.BufferedImage ; 46 import java.io.IOException ; 47 import java.io.OutputStream ; 48 49 55 public class EncoderUtil { 56 57 66 public static byte[] encode(BufferedImage image, String format) 67 throws IOException { 68 ImageEncoder imageEncoder = ImageEncoderFactory.newInstance(format); 69 return imageEncoder.encode(image); 70 } 71 72 82 public static byte[] encode(BufferedImage image, String format, 83 boolean encodeAlpha) throws IOException { 84 ImageEncoder imageEncoder 85 = ImageEncoderFactory.newInstance(format, encodeAlpha); 86 return imageEncoder.encode(image); 87 } 88 89 99 public static byte[] encode(BufferedImage image, String format, 100 float quality) throws IOException { 101 ImageEncoder imageEncoder 102 = ImageEncoderFactory.newInstance(format, quality); 103 return imageEncoder.encode(image); 104 } 105 106 118 public static byte[] encode(BufferedImage image, String format, 119 float quality, boolean encodeAlpha) 120 throws IOException { 121 ImageEncoder imageEncoder 122 = ImageEncoderFactory.newInstance(format, quality, encodeAlpha); 123 return imageEncoder.encode(image); 124 } 125 126 134 public static void writeBufferedImage(BufferedImage image, String format, 135 OutputStream outputStream) throws IOException { 136 ImageEncoder imageEncoder = ImageEncoderFactory.newInstance(format); 137 imageEncoder.encode(image, outputStream); 138 } 139 140 150 public static void writeBufferedImage(BufferedImage image, String format, 151 OutputStream outputStream, float quality) throws IOException { 152 ImageEncoder imageEncoder 153 = ImageEncoderFactory.newInstance(format, quality); 154 imageEncoder.encode(image, outputStream); 155 } 156 157 167 public static void writeBufferedImage(BufferedImage image, String format, 168 OutputStream outputStream, boolean encodeAlpha) throws IOException { 169 ImageEncoder imageEncoder 170 = ImageEncoderFactory.newInstance(format, encodeAlpha); 171 imageEncoder.encode(image, outputStream); 172 } 173 174 186 public static void writeBufferedImage(BufferedImage image, String format, 187 OutputStream outputStream, float quality, boolean encodeAlpha) 188 throws IOException { 189 ImageEncoder imageEncoder 190 = ImageEncoderFactory.newInstance(format, quality, encodeAlpha); 191 imageEncoder.encode(image, outputStream); 192 } 193 194 } 195 | Popular Tags |