有什么快速简便的方法来捕获屏幕的一部分吗? getPixel 很慢,而且 GetDIBits 作为开始似乎有点复杂

发布于 2024-07-20 06:07:00 字数 228 浏览 6 评论 0原文

我尝试使用一些代码在 Windows 上使用 getPixel 捕获部分屏幕,设备上下文为空(捕获屏幕而不是窗口),但速度非常慢。 看起来 GetDIBits() 可以很快,但似乎有点复杂......我想知道是否有一个库可以将整个区域放入数组中,并且 Pixel[x][y] 将返回 24 位颜色像素的代码?

或者 Mac 上是否存在这样的库? 或者如果 Ruby 或 Python 已经有这样的库可以做到这一点?

I was trying some code to capture part of the screen using getPixel on Windows, with the device context being null (to capture screen instead of window), but it was really slow. It seems that GetDIBits() can be fast, but it seems a bit complcated... I wonder if there is a library that can put the whole region into an array, and pixel[x][y] will return the 24 bit color code of the pixel?

Or does such library exist on the Mac? Or if Ruby or Python already has such a library that can do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

箹锭⒈辈孓 2024-07-27 06:07:00

我从未这样做过,但我会尝试:

  1. 创建内存设备上下文(DC)
    使用 CreateCompatibleDC 传递它
    桌面的设备上下文
    (GetDC(NULL))。

  2. 创建位图(使用
    创建兼容位图)相同
    大小作为您捕获的区域。

  3. 选择位图到你的DC中
    创建(使用 SelectObject)。

  4. 从以下位置执行 BitBlt
    桌面 DC 到您创建的 DC(使用 SRCCOPY 标志)。

如果您以错误的顺序执行操作,则使用设备上下文可能会导致 GDI 泄漏,因此请确保阅读有关您使用的所有 GDI 函数(例如 SelectObject、GetDC 等)的文档。

I've never done this but I'd try to:

  1. Create a memory Device Context (DC)
    using CreateCompatibleDC passing it
    the Device Context of the desktop
    (GetDC(NULL)).

  2. Create a Bitmap (using
    CreateCompatibleBitmap) the same
    size as the region your capturing.

  3. Select the bitmap into the DC you
    created (using SelectObject).

  4. Do a BitBlt from the
    desktop DC to the DC you created (using SRCCOPY flag).

Working with Device Contexts can cause GDI leaks if you do things in the wrong order so make sure that you read the documentation on all the GDI functions you use (e.g. SelectObject, GetDC, etc.).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文