BufferedImage byte[] 互转
BufferedImage byte[] 互转
BufferedImage 转 byte[]
/**
* BufferedImage 转 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[] 转 BufferedImage
/**
* byte[] 转 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;
}
}