从像素缓冲区位块传输到设备上下文的最快方法
晚上好,
我的内存缓冲区中有几个 32 位图像,我希望快速将它们“blit”到设备上下文。速度在这里是一个问题,因为缓冲区将被不断地操作,并且需要重复地传输到 DC。
缓冲区的颜色深度是 32 位,因此它已经是 SetDIBits() 的 DIB 预期格式。然而,这相当麻烦,因为 SetDIBits() 的位图目标不能在操作之前就已经选择到 DC 中。因此,我需要不断地交换 DC 的位图,调用 SetDIBits(),将位图交换回 DC,然后将 DC 位图传输到 Window 的 DC。对我来说,这似乎是 CPU 上的大量工作负载以及 Windows API 中的太多分支;对于最佳性能来说太多了。
如果 DirectX 不强迫我使用设备上下文进行 2D 操作,或者在显示纹理之前将纹理上传到视频内存,我会对使用 DirectX 感兴趣,因为图像的内容不断变化。
我的问题很简单(尽管写得很长)。对于我来说,将图像从内存中的像素缓冲区传输到屏幕上的最快方法是什么?直接访问 DC 的像素缓冲区会很棒,但我知道这不会发生。
感谢您阅读我的长文。
Good evening,
I have several 32-bit images in memory buffers that I wish to "blit" to a device context, quickly. Speed is an issue here because the buffer will be manipulated constantly and need to be blitted to the DC repeatedly.
The color depth of the buffer is 32-bits, so it is already in the DIB-expected format of SetDIBits(). However, this is rather cumbersome since the bitmap target of SetDIBits() cannot be already selected into the DC prior to the operation. So I will need to constantly swap out the DC's bitmap, call SetDIBits(), swap the bitmap back into the DC, and then blit the DC to the Window's DC. To me, that just seems like a LOT of workload on the CPU and too much branching in the Windows API; way too much for optimal performance.
I would be interested in using DirectX if it didn't force me to use Device Contexts for 2D operations, or uploading textures to video memory before displaying them, because the contents of the image are constantly changing.
My question is simple (despite the long writeup). What would be the fastest way for me to blit an image from a pixel buffer in memory onto the screen? Direct access to the pixel buffer of a DC would be great, but I know that's not going to happen.
Thanks for reading my long writeup.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一个 API 方法 CreateDIBSection 来创建应用程序可以直接写入的 DIB。这允许连续更新位图(内存复制或直接写入)。
请参阅 MSDN 文章了解更多详细信息。
There is an API method CreateDIBSection to create a DIB that applications can write to directly. This allows to continuously updating the bitmap (either memcopy or directly writing to it).
See MSDN article for further details.