[atl/wtl]_[0 base]_[cbitmap Copy image-capture image-tile picture]

Source: Internet
Author: User


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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.