I'm looking to speed up a Bitmap displaying program. It's not dreadfully slow, I just think it could be faster. I run it in a Win32 environment. Here's the code:
void load(LPCWSTR file, int i) {
hBitmap[i] = (HBITMAP)::LoadImage(NULL, file, IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE);
GetObject(hBitmap[i], sizeof(BITMAP), (LPSTR)&hSize[i]);
}
void newBit(int i, int x, int y, HDC hdc) {
BITMAP Bitmap = hSize[i];
HBITMAP hBit = hBitmap[i];
HDC hDCBits = CreateCompatibleDC(hdc);
SelectObject(hDCBits, hBit);
StretchBlt(hdc, x, y, Bitmap.bmWidth, Bitmap.bmHeight,
hDCBits, 0, 0, Bitmap.bmWidth, Bitmap.bmHeight, SRCCOPY);
DeleteDC(hDCBits);
}
I run the "Load" function in the beginning, and I'm okay with how long it takes. I run the newBit function whenever in the program that I need to. I specifically use the stretchBlt command because I need the resizing capability. Any insight into what I'm doing wrong and what I could improve would be appreciated.
Since I suspect it has to do something with your previous question here, I post following answer.
If you want to create some animation in your window and want to speed things up, consider using GDI+ instead just plain winapi. With GDI+ you just put your drawing methods in
WM_PAINT
message and update your scene with invalidating your control rect and updating the window.For example something like that:
WM_PAINT message handling could look like this for example:
To avoid flickering, you should tell winapi not to erase background like so: