简体   繁体   English

比GetPixel()快?

[英]Faster than GetPixel()?

How would I replace GetPixel() with something faster? 如何用更快的速度替换GetPixel()

Currently I am using: 目前,我正在使用:

temp = GetPixel(hMonitor, 1, 1);
if (pixelArray[0] != temp)
{
    pixelArray[0] = temp;
    counter++;
}

Above code is just a simplified example. 上面的代码只是一个简化的示例。

This is contained in a for loop for all the pixels on the display. 它包含在显示器上所有像素的for循环中。 It compares one pixel (temp) against the previous array's pixel (pixelArray). 它将一个像素(温度)与前一个数组的像素(pixelArray)进行比较。 If it has changed, then replace it. 如果已更改,请更换它。 How-ever I am finding that using GetPixel() for every pixel on the display takes a long time. 但是,我发现对显示器上的每个像素使用GetPixel()会花费很长时间。

I have been reading other questions of a similar nature such as: 我一直在阅读其他类似性质的问题,例如:

Fastest method of screen capturing 最快的屏幕捕获方法

Get Pixel color fastest way? 快速获得像素颜色?

...but I am not sure which method is better such as GDI or DirectX nor how I would implement said methods. ...但是我不确定哪种方法更好,例如GDI或DirectX,也不确定如何实现上述方法。

Update: Windows GDI (using GetObject) to an array of the pixels is what I needed, thank you. 更新:我需要Windows GDI(使用GetObject)到像素数组,谢谢。 This is much, much faster than GetPixel(). 这比GetPixel()快得多。

I would suggest you retrieve a pointer to the bitmap's pixel data (assuming you have a HBITMAP handle). 我建议您检索一个指向位图像素数据的指针(假设您具有HBITMAP句柄)。

This is done via GetObject() , which should return you a BITMAP structure . 这是通过GetObject()完成的 ,它应该返回一个BITMAP结构 This is the field you are interested in: 这是您感兴趣的领域:

bmBits : A pointer to the location of the bit values for the bitmap. bmBits :指向位图的位值的位置的指针。 The bmBits member must be a pointer to an array of character (1-byte) values. bmBits成员必须是指向字符(1字节)值数组的指针。

Then you can run your checking logic per pixel on the buffers. 然后,您可以在缓冲区上按像素运行检查逻辑。 That would be way faster from using GetPixel. 这将比使用GetPixel更快。

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

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