/** * Encodes an image in PNG format. * * @param bufferedImage The image to be encoded. * @return The byte[] that is the encoded image. * @throws IOException */ public byte[] encode(BufferedImage bufferedImage) throws IOException { if (bufferedImage == null) { throw new IllegalArgumentException("Null 'image' argument."); } PngEncoder encoder = new PngEncoder(bufferedImage, this.encodingAlpha, 0, this.quality); return encoder.pngEncode(); }
/** * Encodes an image in PNG format and writes it to an <code>OutputStream</code>. * * @param bufferedImage The image to be encoded. * @param outputStream The OutputStream to write the encoded image to. * @throws IOException */ public void encode(BufferedImage bufferedImage, OutputStream outputStream) throws IOException { if (bufferedImage == null) { throw new IllegalArgumentException("Null 'image' argument."); } if (outputStream == null) { throw new IllegalArgumentException("Null 'outputStream' argument."); } PngEncoder encoder = new PngEncoder(bufferedImage, this.encodingAlpha, 0, this.quality); outputStream.write(encoder.pngEncode()); }