Is there any Win32 API function that will allow me to load a subsection of a bitmap (specifying width, height, and x,y) without resorting to directly manipulating the bitmapped data?
Printable View
Is there any Win32 API function that will allow me to load a subsection of a bitmap (specifying width, height, and x,y) without resorting to directly manipulating the bitmapped data?
Get the current screen DC. Create a memory DC which is compatible with the screen DC. Create a compatible bitmap. Load your bitmap into the memory DC and use BitBlt() to copy whichever rectangles you want.
Lookup GetDC(), CreateCompatibleDC(), CreateCompatibleBitmap(), SelectObject(), BitBlt(), ReleaseDC(), DeleteDC(), DeleteObject().
Adrian is right but you need two DC's. One for the final image and one temp.
If you want you can create the DC as Adrian says, then just select the BMP into it (catching the return) rather than creating a compatible bitmap.
Then use BitBlt() or the less satisfactory StretchBlt() to copy the relevent section to your framebuffer DC.
Reselect the original BMP and clean up the GDI's.
I find GetObject() is handy to find the dimensions of the BMP.
GetObject(hBMP,sizeof(BITMAP),&BMP);
iWidth=BMP.bmWidth;// ect