Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StretchDIBits seems slow, Is there any API faster?

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)
like image 353
user25749 Avatar asked May 13 '09 09:05

user25749


1 Answers

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.

like image 198
Adrian McCarthy Avatar answered Nov 15 '22 08:11

Adrian McCarthy