为什么使用 Ruby(也可能是 Perl 或 Python)的 GetPixel() 如此慢以及如何通过其他方法来实现?

发布于 2024-08-13 17:44:03 字数 146 浏览 2 评论 0原文

我尝试将 Win32 的 GetPixel() 与 Ruby 一起使用,即使在四核 Intel 机器上,它也非常慢。我想,例如,如果我得到一个非常小的区域,例如 100 x 10 像素 = 1000 像素,则可能需要 30 秒才能完成。有没有更好的方法,例如一次性获取一个区域?

I tried using Win32's GetPixel() with Ruby and it is really slow even on a Quad Core Intel machine. I think for example, if I get a really small region such as 100 x 10 pixels = 1000 pixels and it can take 30 seconds to complete. Is there a better way such as by getting a region all at once?

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

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

发布评论

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

评论(2

初心未许 2024-08-20 17:44:03

我认为你想要的功能是BitBlt。

I think the function you want is BitBlt.

梦醒灬来后我 2024-08-20 17:44:03

我对Ruby了解不多,但是它不是解释型的吗?如果是这样,并且您通过可能的 Ruby 库之一调用 Win32 API 调用,并且在此基础上调用 GetPixel,那么是的,速度会很慢。

如果您可以通过 Ruby 访问 Win32 api,那么您应该研究一下 BitBlt。位块传输将返回值的缓冲区而不是单个值。这会快很多倍。

当然,现在您必须处理设备上下文、位图结构和原始内存,这些可能是比 Ruby 提供的更低级别的构造。

http://winprog.org/tutorial/bitmaps.html

I don't know much about Ruby, but isn't it interpreted? If it is and you are invoke a Win32 API call through presumable one of Rubys librarys and on top of that calling GetPixel, well then yes, it would be slow.

If you have access to the Win32 api's through Ruby then you should look into BitBlt. Bit-Block-Transfer which will return a buffer of values rather than individual values. This will be many times faster.

Of course, now you have to deal with Device Context's, Bitmap structures and raw memory, which are perhaps lower level constructs than Ruby provides for.

http://winprog.org/tutorial/bitmaps.html

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