为什么使用 Ruby(也可能是 Perl 或 Python)的 GetPixel() 如此慢以及如何通过其他方法来实现?
我尝试将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你想要的功能是BitBlt。
I think the function you want is BitBlt.
我对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