[ATL/wtl] _ [cbitmap copying images-capturing images-tiled images]

Source: Internet
Author: User


Scenario:

1. When you need to take part of the image area as the background of a widget.

2. You need to tile the image to a large area so that it can be automatically zoomed in.

3. or you need to merge images.


Code:

CDC sdc; CDC ddc;sdc.CreateCompatibleDC(NULL);ddc.CreateCompatibleDC(NULL);CBitmap destBmp;destBmp.CreateCompatibleBitmap(CClientDC(NULL),width,height);sdc.SelectBitmap(m_Bitmap);ddc.SelectBitmap(destBmp);ddc.BitBlt(0, 0, width, height, sdc, rect.left, rect.top, SRCCOPY );


Note: When destbmp calls createcompatiblebitmap, the first parameter passed in is cclientdc. Otherwise, the new cbitmap will not be what you want.

The following section describes how to copy hbitmap objects using the mfc api. Some codes are 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);destDC.CreateCompatibleDC(NULL);//The bitmap information.BITMAP bm = {0};//Get the bitmap information.::GetObject(hSourceHbitmap, sizeof(bm), &bm);// Create a bitmap to hold the resultHBITMAP hbmResult = ::CreateCompatibleBitmap(CClientDC(NULL), width, height);HBITMAP hbmOldSource = (HBITMAP)::SelectObject( sourceDC.m_hDC, hSourceHbitmap);HBITMAP hbmOldDest = (HBITMAP)::SelectObject( destDC.m_hDC, hbmResult );destDC.BitBlt(0,0,width, height, sourceDC, srcx, srcy, SRCCOPY );// Restore DCs::SelectObject( sourceDC.m_hDC, hbmOldSource );::SelectObject( destDC.m_hDC, hbmOldDest );::DeleteObject(sourceDC.m_hDC);::DeleteObject(destDC.m_hDC);return hbmResult;}



[ATL/wtl] _ [cbitmap copying images-capturing images-tiled images]

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.