Bitblt() is faster then SetDIBitsToDevice()?
In my application, I will periodically receive data from an external
device. The data is actually an two dimensional array, and it's storage
structure is just like raster data in an DIB image. such as
row0: RGBRGBRGB......
row1: RGBRGBRGB......
row2: RGBRGBRGB......
.......
Now, I have two kinds of method to paint this *raw data* to a window.
I will demonstrate them in pseudo code:
First method, I will call SetDIBitsToDevice() directly.
/////////////////////////////////////////////////////////
int nSize = Rows * Columns * 3;
pBuffer = new char[nSize]; //allocate a buffer
BITMAPINFO bmi;
Fill bmi......
while(bRunning){
ReceiveFromDevice(pBuffer);
SetDIBitsToDevice(
targetDC,
....,
pBuffer,
&bmi,
DIB_RGB_COLORS );
}
////////////////////////////////////////////////////////
Second method, I use a Dibsection
///////////////////////////////////////////////////////
hBitmap = ::CreateDIBSection(...);
BITMAP = GetObject(hBitmap,...);
pBuffer = BITMAP.bmBits; // Get the pointer to buffer
while(bRunning){
ReceiveFromDevice(pBuffer);
CDC dcMem;
dcMem.CreateCompatibleDC(pdc);
dcMem.SelectObject(hBitmap);
pDC->Bitblt(...,&dcMem...);
......
}
//////////////////////////////////////////////////////
I don't know which method is the best, and runs faster?
I do find a web link talk about this issue:
http://msdn.microsoft.com/en-us/library/ms532354(VS.85).aspx
It suggest that bitblt is faster.
"......For example, a multimedia application that combines animated
graphics with sound would benefit from calling the BitBlt function
because it executes faster than SetDIBitsToDevice...."
But I don't know why? Thanks for any suggestions!