我需要从 BufferedImage 中获取像素数据,以便根据数据重新创建图像。我查看了 Raster
,但它似乎没有包含我需要的信息。如何从 BufferedImage
获取数据,以便在不需要原始文件的情况下重新创建图像?
最佳答案
你应该看看这个问题的答案
Java - get pixel array from image
一种方法是使用
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(originalImage, "jpg", baos);
baos.flush();
byte[] imageBytes = baos.toByteArray();
baos.close();
现在当你想从你使用的数据中创建一个新的BufferedImage
ByteArrayInputStream bais = new ByteArrayInputStream(imageBytes);
BufferedImage newImage = null;
try {
newImage = ImageIO.read(bais);
} catch (IOException e) {
// handle exception
}
关于java - 从 BufferedImage 获取像素数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19623754/