java类型转换
程序员文章站
2022-03-14 15:55:38
...
(1)MultipartFile->BufferedImage
BufferedImage bufferedImage=ImageIO.read(imageFile.getInputStream());
(2)BufferedImage–>byte[]
/**
* 类型转换,BufferedImage-->byte[]
* @param bufferedImage BufferedImage 原始image
* @param Suffix 图片类型,如jpg,png
* @return byte[] 字节数组
*/
private static byte[] BufferedImageToBytes(BufferedImage bufferedImage,String Suffix) throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, Suffix, byteArrayOutputStream);
byteArrayOutputStream.flush();
byte[] bytes = byteArrayOutputStream.toByteArray();
byteArrayOutputStream.close();
return bytes;
}
(3)byte[]–>List
List<Byte> list = new ArrayList<>();
for (byte b : bytes) {
list.add(b);
}
上一篇: 16进制与字符串相互转换(C语言)
下一篇: 算法笔记 — 又一版 A+B