StretchDIBits seems slow, Is there any API faster?

天涯浪子 提交于 2019-12-22 06:20:41

问题


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);

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?

just as

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

回答1:


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).

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

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.



来源:https://stackoverflow.com/questions/856938/stretchdibits-seems-slow-is-there-any-api-faster

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!