如何从PNG文件中读取像素? [英] How do I read pixels from a PNG file?

查看:1598
本文介绍了如何从PNG文件中读取像素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何使用Robot,Windowtester或FEST捕获屏幕截图。我也知道如何使用机器人从屏幕上读取像素。

I know how to capture a screenshot by using Robot, Windowtester or FEST. I also know how to read a pixel from the screen by using robot.

int x = 10;
int y = 10; 
Color px = getPixelColor(int x, int y);

但是,我不知道如何从已捕获的图像中读取像素。我打算将当前图像与文件中的图像进行比较。让我们说两者都是PNG。是否有任何框架可用于逐像素地比较图像?

However, I don't know how to read a pixel from an image that is already captured. I'm planning to compare a current image, with an image from file. Lets say both are PNG. Are there any frameworks that I can use to compare images pixel by pixel?

推荐答案

这是用Java吗?如果是这样,您可以使用 ImageIO.read(yourImage.png)来获取 BufferedImage 。这将有一个 getData()方法,它将为您提供 Raster 对象,您可以在其上调用 getPixel 。参见链接

Is this in Java? If so, you can use ImageIO.read( "yourImage.png" ) to get a BufferedImage. That will have a getData() method which will give you a Raster object, on which you can call getPixel. See link

这篇关于如何从PNG文件中读取像素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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