Added BufferedImage.toBytes() method
This commit is contained in:
parent
14c0fea0b6
commit
84911327b4
@ -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.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user