Scene:
1. When you need to intercept a picture part of the area as the background of a control.
2. You need to tile the picture into a large area to let him zoom in on his own initiative.
3. Or if you need to merge pictures.
Code:
CDC SDC; CDC DDC;SDC. CreateCompatibleDC (NULL);dd C. CreateCompatibleDC (NULL); CBitmap Destbmp;destbmp.createcompatiblebitmap (CClientDC (NULL), width,height), SDC. Selectbitmap (M_bitmap);dd C. Selectbitmap (destbmp);dd C. BitBlt (0, 0, width, height, SDC, Rect.left, Rect.top, srccopy);
Note: Here's one thing to note. is destbmp when calling CreateCompatibleBitmap, the first parameter passed in is CCLIENTDC, otherwise the generated new CBitmap will not be what you want.
Below is the MFC API copy Hbitmap object, part of the code from the Internet.
Copy the Hbitmap object.
Static Hbitmap Copybitmap (hbitmap hsourcehbitmap,long width,long height,int srcx,int srcy) {CDC SourceDC; CDC Destdc;sourcedc.createcompatibledc (NULL);d ESTDC.CREATECOMPATIBLEDC (null),//the bitmap information. BITMAP BM = {0};//get the BITMAP information.::getobject (hsourcehbitmap, sizeof (BM), &BM);//Create a BITMAP to hold T He resulthbitmap Hbmresult =:: CreateCompatibleBitmap (CClientDC (NULL), width, height); Hbitmap Hbmoldsource = (HBITMAP):: SelectObject (SOURCEDC.M_HDC, Hsourcehbitmap); Hbitmap hbmolddest = (HBITMAP):: SelectObject (DESTDC.M_HDC, Hbmresult);d estdc.bitblt (0,0,width, height, SourceDC, SRCX , Srcy, srccopy);//Restore Dcs::selectobject (SOURCEDC.M_HDC, Hbmoldsource);:: SelectObject (DESTDC.M_HDC, HbmOldDest) ;::D Eleteobject (SOURCEDC.M_HDC);::D Eleteobject (DESTDC.M_HDC); return hbmresult;}
[atl/wtl]_[0 base]_[cbitmap Copy picture-capture picture-tile picture]