c++ - 比 GetPixel() 更快?

标签 c++ windows directx gdi

我如何用更快的东西替换 GetPixel()

目前我正在使用:

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

以上代码只是一个简化的例子。

这包含在显示器上所有像素的 for 循环中。它将一个像素 (temp) 与前一个数组的像素 (pixelArray) 进行比较。如果已更改,则更换它。然而,我发现对显示器上的每个像素使用 GetPixel() 需要很长时间。

我一直在阅读其他类似性质的问题,例如:

Fastest method of screen capturing

Get Pixel color fastest way?

...但我不确定哪种方法更好,例如 GDI 或 DirectX,也不确定我将如何实现这些方法。

更新:Windows GDI(使用 GetObject)到像素数组是我所需要的,谢谢。这比 GetPixel() 快得多。

最佳答案

我建议您检索指向位图像素数据的指针(假设您有一个 HBITMAP 句柄)。

这是通过 GetObject() 完成的,它应该返回一个 BITMAP structure .这是您感兴趣的领域:

bmBits: A pointer to the location of the bit values for the bitmap. The bmBits member must be a pointer to an array of character (1-byte) values.

然后您可以在缓冲区上按像素运行检查逻辑。使用 GetPixel 会更快。

关于c++ - 比 GetPixel() 更快?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26727293/

相关文章:

c++ - MPI_Comm_spawn 失败,返回 "All nodes which are allocated for this job are already filled"

c++ - DirectX 中的多个着色器与多种技术

c++ - 你如何获得网格的顶点缓冲区?

c++ - libsvm : C++ vs. MATLAB : What's With The Different Accuracies?

c++ - 如何在不考虑 session 的情况下获取显示设备信息?

c++ - QStyledItemDelegate 绘图自定义小部件失败

c# - Directory.EnumerateFiles 异常

c++ - 主板 ID - WMI C++ - 可靠吗?

c++ - GlBufferDataARB 给我内存问题

c# - 在 DirectX 中渲染环境