我试图在屏幕上获取一小部分图像并读取任何像素以比较其他像素。获取屏幕图像的代码是:
Rectangle captureSize = new Rectangle(x, y, height, width);
BufferedImage image = robot.createScreenCapture(captureSize);
而且,为了逐个像素地读取我使用的
for (int y = 0; y < image.getHeight(); y = y + 1) {
for (int x = 0; x < image.getWidth(); x = x + 1) {
color = image.getRGB(x, y);
// Some methods etc
{
{
但是,当我运行它时,我感到震惊。因为createScreenCapture
大约需要40 毫秒getRGB
,每个像素的使用大约需要350 毫秒,这对于创建 60 fps 的应用程序来说非常低效。顺便说一句,我的图像是800x400像素大小。我没有尝试
rgbArray = image.getRGB(startX, startY, w, h, rgbArray,offset, scansize) ;
方法,因为我不知道它的效率如何,并且重新排序我的代码会有点困难。因此,任何帮助将不胜感激。