简体   繁体   English

在屏幕上快速收集图像并读取像素

[英]Fast gathering image on screen and reading the pixels

I'm trying to get a small section of image on the screen and read any pixel to compare the other pixels.The code to get screen image is:我正在尝试在屏幕上获取一小部分图像并读取任何像素以比较其他像素。获取屏幕图像的代码是:

Rectangle captureSize = new Rectangle(x, y, height, width);
BufferedImage image = robot.createScreenCapture(captureSize);

And, to read pixel by pixel I used而且,为了逐个像素地读取我使用的

  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
        {
{

However, when I ran it I was shocked.但是,当我运行它时,我感到震惊。 Because createScreenCapture took about 40 ms and using getRGB of each pixel took around 350 ms which is very inefficient to create an application for 60 fps.因为createScreenCapture大约需要40 毫秒,而使用每个像素的getRGB大约需要350 毫秒,这对于创建 60 fps 的应用程序来说非常低效。 By the way, my image is 800x400 pixels size.顺便说一句,我的图像是800x400像素大小。 I didn't try我没有尝试

rgbArray = image.getRGB(startX, startY, w, h, rgbArray,offset, scansize) ;

method because I don't know how efficient it is and to reorder my code would be a bit difficult.方法,因为我不知道它的效率如何,并且重新排序我的代码会有点困难。 So, any help would be appreciated.因此,任何帮助将不胜感激。

Use利用

rgbArray = image.getRGB(startX, startY, w, h, rgbArray,offset, scansize) ;

It will be much faster to read the pixel values from the array than to do the method call to get each pixel value, and the single call to getRGB to fetch the array is not slow.从数组中读取像素值比通过方法调用获取每个像素值要快得多,并且单次调用 getRGB 来获取数组并不慢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM