diff --git a/src/dorkbox/util/ImageUtil.java b/src/dorkbox/util/ImageUtil.java index 688ac51..7eb3cc8 100644 --- a/src/dorkbox/util/ImageUtil.java +++ b/src/dorkbox/util/ImageUtil.java @@ -22,6 +22,7 @@ import java.awt.Graphics2D; import java.awt.Image; import java.awt.RenderingHints; import java.awt.image.BufferedImage; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -305,6 +306,18 @@ class ImageUtil { return bimage; } + /** + * Converts an image to a byte array + * + * @return the PNG File output the created buffered image, as a byte array + */ + public static + byte[] toBytes(final BufferedImage image) throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + ImageIO.write(image, "PNG", byteArrayOutputStream); + return byteArrayOutputStream.toByteArray(); + } + /** * Reads the image size information from the specified file, without loading the entire file. *