BufferedImage byte[] 互轉(zhuǎn)
BufferedImage 轉(zhuǎn) byte[]
/**
* BufferedImage 轉(zhuǎn) byte[]
*
* @param bImage
* @return byte[]
* @author 云深小麥
*/
public static byte[] imageToBytes(BufferedImage bImage) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
ImageIO.write(bImage, "jpg", byteArrayOutputStream);
return byteArrayOutputStream.toByteArray();
} catch (IOException ignored) {
return null;
}
}
byte[] 轉(zhuǎn) BufferedImage
/**
* byte[] 轉(zhuǎn) BufferedImage
*
* @param bytes
* @return BufferedImage
* @author 云深小麥
*/
public static BufferedImage bytesToImage(byte[] bytes) {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
try {
return ImageIO.read(byteArrayInputStream);
} catch (IOException ignored) {
return null;
}
}