【问题标题】:Is there a way to replace an image's pixel with a file/bufferedreader?有没有办法用文件/缓冲读取器替换图像的像素?
【发布时间】:2017-02-08 03:09:59
【问题描述】:

我正在尝试构建其中一个合成图像程序,您可以在其中输入 X 图像,它会从这些图像中制作出另一张照片。现在,我已经掌握了从比较方程到从源文件夹中获取文件进行比较的所有内容,但我似乎无法弄清楚如何用我已经拥有的图像替换单个像素。如果这可以通过缓冲图像/文件来完成,怎么做?如果没有,还有其他方法可以实现吗?

【问题讨论】:

  • 读取文件会是一个问题,因为许多文件格式是压缩的,并不总是以线性方式存储图像数据。您可以使用ImageIO 加载图像,这将为您提供BufferedImage,或者可能有其他可用的库不必加载整个图像以便您操作它
  • 我建议也使用ImageIOBufferedImages,但在开始之前阅读Java2D 教程中的Working with ImagesCompositing。 PS:一些(未压缩的)格式可能支持replacing pixels through the ImageWriter API,但我认为你还不需要这个..

标签: java bufferedimage pixels


【解决方案1】:
//create simple image
BufferedImage img = new BufferedImage(320, 240, BufferedImage.TYPE_INT_RGB);
//set pixel color RED at x=10, y=10
img.setRGB(10, 10, Color.red.getRGB());

//get pixel color as RGB
int rgb = img.getRGB(50, 50);

//get components of RGB as separated R, G and B values
int red = (rgb >> 16) & 0xFF;
int green = (rgb >> 8) & 0xFF;
int blue = rgb & 0xFF;

【讨论】:

  • 抱歉,澄清一下,我有一个空的 Bufferedimage 对象,我想用其他 BufferedImage 填充它。有没有办法将 BufferedImage 中的像素设置为另一个 BufferedImage 对象或类似的东西?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-07-04
  • 1970-01-01
  • 2022-01-19
  • 1970-01-01
  • 1970-01-01
  • 2010-12-22
  • 1970-01-01
相关资源
最近更新 更多