问题
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