Re: Bitblt() is faster then SetDIBitsToDevice()?
I think that in cases like this doing some benchmarking and test is the best
thing to do...
I would like to suggest also to try DirectDraw. DirectDraw can blit 2D
surfaces very fast, e.g. using IDirectDrawSurface::BltFast() method.
Giovanni
"asm23" <asmwarrior@gmail.com> ha scritto nel messaggio
news:gb0bik$o1j$1@aioe.org...
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!