一、byte[] 数据转 图像文件
byte[] data;
data里面放得是图片数据。
InputStream buffin = new ByteArrayInputStream(data);
BufferedImage img = ImageIO.read(buffin);
File destimage = new File("e:\\source.jpg");
ImageIO.write(img, "jpg", destimage);
二、图像文件 转 byte[] 数据
BufferedImage pic = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
在pic中写画图像
ByteArrayOutputStream bao = new ByteArrayOutputStream();
try {
ImageIO.write(pic, "JPEG", bao);
} catch (IOException e) {
e.printStackTrace();
}
byte[] data = bao.toByteArray();
本文介绍如何将byte[]数据转换为图像文件,并反向操作。首先展示使用Java的ByteArrayInputStream与ImageIO进行byte[]到图像文件的转换流程;其次,详细说明从创建空白图像到将其转换为byte[]的过程。

2万+

被折叠的 条评论
为什么被折叠?



