从BufferedImage获取像素数据 [英] Get pixel data from a BufferedImage

查看:85
本文介绍了从BufferedImage获取像素数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从BufferedImage获取像素数据,以便可以从数据重新创建图像.我查看了 Raster ,但这似乎不包含我需要的信息.如何从 BufferedImage 获取数据,以便无需原始文件即可重新创建图像?

I need to obtain the pixel data from a BufferedImage so I can recreate the image from the data. I looked into Raster, but that did not seem to contain the information I need. How can I obtain data from a BufferedImage so I can recreate the image without needing the original file?

推荐答案

您应该查看该问题的答案

You should check out the answers to this question

Java-从图像获取像素阵列

一种方法是使用

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

现在,当您想根据使用的数据创建新的 BufferedImage

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
}

这篇关于从BufferedImage获取像素数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆