两幅位对象的每像素的基础上快速比较 [英] Fast comparison of two Bitmap objects on a pixel per pixel basis

查看:103
本文介绍了两幅位对象的每像素的基础上快速比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在实施接受两个位图对象的方法。我们可以假设,所述对象是相等的尺寸的等方法的返回是像素变化的列表(此存储在自制对象)。这是在一个迭代的方式正在开发使目前的实现是一个基本的...只是通过每一个像素工作,并比较其对应。这产生变化的方法比可以接受的(500毫秒左右)更慢,因此我在找一个更快的过程。

I am currently implementing a method that accepts two bitmap objects. We can assume that said objects are of equal dimensions etc. The return of the method is a list of Pixel changes (this is stored in a self-made object). This is being developed in an iterative manner so the current implementation was a basic one... simply work through each pixel and compare it to its counterpart. This method for generating changes is slower than acceptable (500ms or so), as such I am looking for a faster process.

这已经越过我的脑海思想是将图像分解成条状,并运行在一个新的线程每个比较或屏幕区作为比较对象,第一个然后根据需要在细节仅检查。

Ideas that have crossed my mind are to break down the image into strips and run each comparison on a new thread or to compare zones of the screen as objects first then only examine in detail as required.

目前的code的理解...

current code for your understanding...

   for (int x = 0; x < screenShotBMP.Width; x++)
   {
       for (int y = 0; y < screenShotBMP.Height; y++)
       {
           if (screenShotBMP.GetPixel(x, y) != _PreviousFrame.GetPixel(x, y))
           { 
             _pixelChanges.Add(new PixelChangeJob(screenShotBMP.GetPixel(x,y), x, y));
           }
       }
   }

正如您将从code有问题的类的概念扣除是采取截图,并生成从previously采取截图。

As you will deduct from the code the concept of the class in question is to take a screenshot and generate a list of pixel changes from the previously taken screenshot.

推荐答案

您绝对应该看 Lockbits < /操纵位图数据的>方法。

You should definitely look at the Lockbits method of manipulating bitmap data.

有数量级比GetPixel /更快的setPixel

It is orders of magnitude faster than GetPixel/SetPixel.

编辑:结果
检查<一href=\"http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/bd0eec9e-f811-4fab-a245-08b2882d005c\"相对=nofollow>对于一些code此链接
(尽管在VB,但你应该得到的漂移),几乎你想要做什么。这只不过是检查两个位图的平等和返回true或false。你可以改变的功能,因此如果需要每个像素检查添加到您的_pixelChanges列表,而返回一个布尔值的列表中。


Check this link for some code (albeit in VB, but you should get the drift) that almost does what you want. It is simply checking two bitmaps for equality and returning true or false. You could change the function so each pixel check adds to your _pixelChanges list if necessary, and return this list instead of a boolean.

另外,如果你换轮迭代循环可能更快。即有内循环遍历X,并在Y中的外循环迭代。

Also, it may be faster if you swap round the iterator loops. i.e. have the inner loop iterating over X, and the outer loop iterating over Y.

这篇关于两幅位对象的每像素的基础上快速比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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