Drawimage bitblt stretchblt Method for painting PNG Images

Source: Internet
Author: User

Add the code to the onpaint () function in the dialog box:

Take my code as an example:

// Graphics

// Use graphics. drawimage

Void userlist: onpaint ()

{

Cpaintdc DC (this); // device context for painting

// Graphics. drawimage

Crect rect;

Getclientrect (& rect );

Graphics graphics (DC. m_hdc );

// Load the PNG Image

Bitmap background (L ". \ userlist \ classlist_top.png ");

Graphics. drawimage (& background, 0, 0, rect. Width (), rect. Height ());

Cdialog: onpaint ();

}

 

Void userlist: onpaint ()

{

Cpaintdc DC (this); // device context for painting

// Load the PNG Image

Bitmap background (L ". \ userlist \ classlist_top.png ");

// Second Method of Drawing bitblt Original Image

Crect RC;

CDC memdc;

Cbitmap;

Cbitmap * poldbmp = NULL;

Hbitmap;

CDC * PDC = getdc ();

// Bitmap to hbitmap

// Hbitmap to cbitmap *

Background. gethbitmap (color (0, 0), & hbitmap); // bitmap to hbitmap

Cbitmap * cbitmap = cbitmap: fromhandle (hbitmap); // hbitmap to cbitmap *

// Display the image

Memdc. createcompatibledc (PDC );

Poldbmp = memdc. SelectObject (cbitmap );

Getclientrect (& rc );

DC. bitblt (0, 0, rect. Width (), rect. Height (), & memdc, 0, 0, srccopy );

// Releasedc

Memdc. SelectObject (poldbmp );

Memdc. deletedc ();

Cbitmap-> deleteobject ();

Cdialog: onpaint ();

}

 

Void userlist: onpaint ()

{

Cpaintdc DC (this); // device context for painting

// Load the PNG Image

Bitmap background (L ". \ userlist \ classlist_top.png ");

// Method 3 for drawing stretchblt tiled Images

Crect RC;

CDC memdc;

Cbitmap;

Cbitmap * poldbmp = NULL;

Hbitmap;

CDC * PDC = getdc ();

// Bitmap to hbitmap

// Hbitmap to cbitmap *

Background. gethbitmap (color (0, 0), & hbitmap); // bitmap to hbitmap

Cbitmap * cbitmap = cbitmap: fromhandle (hbitmap); // hbitmap to cbitmap *

// Display the image

Memdc. createcompatibledc (PDC );

Poldbmp = memdc. SelectObject (cbitmap );

Getclientrect (& rc );

DC. stretchblt (0, 0, rect. Width (), rect. Height (), & memdc, 0, background. getwidth (), Background. getheight (), srccopy );

// Releasedc

Memdc. SelectObject (poldbmp );

Memdc. deletedc ();

Cbitmap-> deleteobject ();

Cdialog: onpaint ();

}

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.