Am I BitBlt'ing Bitmap correctly? wrong code?
Im trying to replace my gdi+ DrawImage() code to BitBlt'ing code to speed things up but my image won't paint to the screen?
Is this the correct code? thanks.
hdc = BeginPaint (hWnd, &ps);
HDC hdcMem = CreateCompatibleDC(hdc);
SelectObject(hdcMem, myBitmap);
BitBlt(hdc, 0, 0, myBitmap->GetWidth(), myBitmap->GetHeight(), hdcMem, 0, 0, SRCCOPY);
DeleteDC(hdcMem);
When I was using DrawImage() everything was fine. but too slow.
Im really am sure this is not the right code.
Re: Am I BitBlt'ing Bitmap correctly? wrong code?
Where is "MyBitmap" defined/initialized?
Re: Am I BitBlt'ing Bitmap correctly? wrong code?
Did the OP call EndPaint()?
Re: Am I BitBlt'ing Bitmap correctly? wrong code?
In SelectObject, you have to pass a HBITMAP handle and not a pointer to Gdiplus::Bitmap object.
Code:
//...
HDC hdcMem = ::CreateCompatibleDC(hdc);
HBITMAP hBitmap = NULL;
Color color;
myBitmap->GetHBITMAP(color, &hBitmap);
HBITMAP hBitmapOld = (HBITMAP)::SelectObject(hdcMem, hBitmap);
::BitBlt(hdc, 0, 0, myBitmap->GetWidth(), myBitmap->GetHeight(), hdcMem, 0, 0, SRCCOPY);
::SelectObject(hdcMem, hBitmapOld);
::DeleteDC(hdcMem);
// ...