StretchDIBits似乎很慢,有没有更快的API? [英] StretchDIBits seems slow, Is there any API faster?

查看:175
本文介绍了StretchDIBits似乎很慢,有没有更快的API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在大小相同的HDC上绘制一个dib. 我在用 : des和src大小相同.

I want to draw a dib on to a HDC, the same size. I am using : des and src are of the same size.

   ::StretchDIBits(hdc,
                des.left,des.top,des.right - des.left,des.bottom - des.top,
                src.left, GetHeight() - src.bottom, src.right - src.left,src.bottom - src.top,
                m_pImg->accessPixels(),m_pImg->getInfo(), DIB_RGB_COLORS, SRCCOPY);

但是我发现它很慢,因为des的大小是一样的,我只需要将dib复制到一个dc上. 有没有比StretchDIBits更快的方法?

but I find it is slow, because the des size is the same, I just need to copy the dib onto a dc. Is there any method faster than StretchDIBits?

StretchBlt (slow)  vs  Bitblt.(faster)
StretchDIBits (slow ) vs ?(faster)

推荐答案

除了处理拉伸所需的一般性之外,速度差异还来自进行任何必要的颜色转换(即使目标尺寸与源尺寸相同)也是如此. ).

The speed difference comes from doing any necessary color conversion in addition to the generality necessary to handle the stretching (even if your target size is the same as your source size).

如果您只绘制一次图像,那么我认为您要查找的功能是SetDIBitsToDevice.

If you're just drawing the image just once, then I think function you're looking for is SetDIBitsToDevice.

如果由于多次绘制相同的DIB而关心速度,则可以通过将DIB复制到兼容的内存DC一次,然后从内存DC到屏幕上BitBlt-来提高性能. (或打印机),每当您需要它.使用CreateCompatibleDC创建内存DC,然后使用StretchDIBitsSetDIBitsToDevice在其上获取图像.之后,您可以直接使用BitBlt.您可能还会考虑使用DIBSECTION,它会在真正的DIB和兼容的DC之间降低性能.

If you care about the speed because you're drawing the same DIB multiple times, then you can improve performance by copying the DIB to a compatible memory DC once, and then BitBlt-ing from the memory DC to the screen (or printer) each time you need it. Use CreateCompatibleDC to create the memory DC, and then use StretchDIBits or SetDIBitsToDevice to get the image on it. After that, you can use BitBlt directly. You might also look into using a DIBSECTION, which gives a compromise in performance between a true DIB and a compatible DC.

这篇关于StretchDIBits似乎很慢,有没有更快的API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆