/** * Retrieve a compressed image from an image. * @param image - the image. * @return A compressed image from an image. * @throws IOException If we were unable to compress the image. */ public static CompressedImage fromPng(RenderedImage image) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); ImageIO.write(image, "png", output); return new CompressedImage("image/png", output.toByteArray()); }
/** * Retrieve a compressed image from an input stream. * @param input - the PNG as an input stream. * @return The compressed image. * @throws IOException If we cannot read the input stream. */ public static CompressedImage fromPng(InputStream input) throws IOException { return new CompressedImage("image/png", ByteStreams.toByteArray(input)); }
/** * Retrieve a compressed image from a byte array of a PNG file. * @param data - the file as a byte array. * @return The compressed image. */ public static CompressedImage fromPng(byte[] data) { return new CompressedImage("image/png", data); }