2

我需要从 BufferedImage 获取像素数据,以便可以从数据中重新创建图像。我查看了Raster,但似乎没有包含我需要的信息。如何从 a 获取数据,BufferedImage以便在不需要原始文件的情况下重新创建图像?

4

1 回答 1

0

You should check out the answers to this question

Java - get pixel array from image

One way to do it is to use

ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(originalImage, "jpg", baos);
baos.flush();
byte[] imageBytes = baos.toByteArray();
baos.close();

Now when you want to create a new BufferedImage from the data you use

ByteArrayInputStream bais = new ByteArrayInputStream(imageBytes);
BufferedImage newImage = null;
try {
    newImage = ImageIO.read(bais);
} catch (IOException e) {
    // handle exception
}
于 2013-10-27T21:32:43.157 回答