Two BMP Overlays

Source: Internet
Author: User

// Create a 24-bit BMP Region

Hbitmap createbitmapsection (HDC, int CX, int cy, byte ** ppbit)

{

Bitmapinfo BMI;

Memset (& BMI. bmiheader, 0, sizeof (bitmapinfoheader ));

BMI. bmiheader. bisize = sizeof (bitmapinfoheader );

BMI. bmiheader. biplanes = 1;

BMI. bmiheader. bibitcount = 24;

BMI. bmiheader. bicompression = bi_rgb;

BMI. bmiheader. biwidth = Cx;

BMI. bmiheader. biheight = Cy;

Return createdibsection (HDC, & BMI, dib_rgb_colors, (void **) ppbit, null, 0 );

}

// Overlay two BMP images and output them to the specified DC. The Alpha value ranges from 0 ~ 255 (0 indicates full transparency, and 255 indicates opacity)

Void transparentpicture (CDC * PDC, hbitmap honebitmap, hbitmap htwobitmap, crect clientrect, int alpha)

{

Bitmap onebitmap;

Bitmap twobitmap;

GetObject (honebitmap, sizeof (Bitmap), & onebitmap );

GetObject (htwobitmap, sizeof (Bitmap), & twobitmap );

Int noneimagewidth = onebitmap. bmwidth;

Int noneimageheight = onebitmap. bmheight;

Int ntwoimagewidth = twobitmap. bmwidth;

Int ntwoimageheight = twobitmap. bmheight;

If (noneimagewidth <ntwoimagewidth)

{

Noneimagewidth = ntwoimagewidth;

}

Else

{

Ntwoimagewidth = noneimagewidth;

}

If (noneimageheight <ntwoimageheight)

{

Noneimageheight = ntwoimageheight;

}

Else

{

Ntwoimageheight = noneimageheight;

}

Int nimagewidth = noneimagewidth;

Int nimageheight = noneimageheight;

CDC memdc1, memdc2;

Hbitmap holdbitmap1 = NULL, holdbitmap2 = NULL;

Byte * ponebits = NULL;

Memdc1.createcompatibledc (PDC );

Memdc2.createcompatibledc (PDC );

Hbitmap honebmp = NULL;

Honebmp = createbitmapsection (PDC-> m_hdc, nimagewidth, nimageheight, & ponebits );

Holdbitmap1 = (hbitmap) SelectObject (memdc1.m _ HDC, honebmp );

Holdbitmap2 = (hbitmap) SelectObject (memdc2.m _ HDC, honebitmap );

// Bitblt (memdc1.m _ HDC, 0, 0, m_ntwoimage_w, m_ntwoimage_h, memdc2.m _ HDC, 0, 0, srccopy );

Stretchblt (memdc1.m _ HDC, 0, 0, nimagewidth, nimageheight,

Memdc2.m _ HDC, 0, 0, onebitmap. bmwidth, onebitmap. bmheight, srccopy );

CDC memdc3, memdc4;

Hbitmap holdbitmap3 = NULL, holdbitmap4 = NULL;

Byte * ptwobits = NULL;

Memdc3.createcompatibledc (PDC );

Memdc4.createcompatibledc (PDC );

Hbitmap htwobmp = NULL;

Htwobmp = createbitmapsection (PDC-> m_hdc, nimagewidth, nimageheight, & ptwobits );

Holdbitmap3 = (hbitmap) SelectObject (memdc3.m _ HDC, htwobmp );

Holdbitmap4 = (hbitmap) SelectObject (memdc4.m _ HDC, htwobitmap );

// Bitblt (memdc3.m _ HDC, 0, 0, m_ntwoimage_w, m_ntwoimage_h, memdc4.m _ HDC, 0, 0, srccopy );

Stretchblt (memdc3.m _ HDC, 0, 0, nimagewidth, nimageheight,

Memdc4.m _ HDC, 0, 0, twobitmap. bmwidth, twobitmap. bmheight, srccopy );

CDC memdc5;

Hbitmap holdbitmap5 = NULL;

Byte * pnewbits = NULL;

Memdc5.createcompatibledc (PDC );

Hbitmap hnewbitmap = NULL;

Hnewbitmap = createbitmapsection (PDC-> m_hdc, nimagewidth, nimageheight, & pnewbits );

Holdbitmap5 = (hbitmap) SelectObject (memdc5.m _ HDC, hnewbitmap );

Int linebytes = 0;

Int Col = 0;

Int line = (nimagewidth * 24) + 31)> 5) <2;

Linebytes = line;

Col = nimageheight;

For (Int J = 0; j <Col; j ++)

{

For (INT I = 0; I <linebytes; I ++)

{

* (Pnewbits + J * line + I) = (* (ponebits + J * line + I) * Alpha +

* (Ptwobits + J * line + I) * (255-alpha)/255;

}

}

Bitblt (PDC-> m_hdc, 0, 0, clientrect. Width (), clientrect. Height (), memdc5.m _ HDC, 0, 0, srccopy );

// Stretchblt (PDC-> m_hdc, 0, 0, m_clientrect.width (), m_clientrect.height (),

//Memdc5.m _ HDC, 0, 0, m_noneimage_w, m_noneimage_h, srccopy );

SelectObject (memdc5.m _ HDC, holdbitmap5 );

Memdc5.deletedc ();

SelectObject (memdc4.m _ HDC, holdbitmap4 );

Memdc4.deletedc ();

SelectObject (memdc3.m _ HDC, holdbitmap3 );

Memdc3.deletedc ();

SelectObject (memdc2.m _ HDC, holdbitmap2 );

Memdc2.deletedc ();

SelectObject (memdc1.m _ HDC, holdbitmap1 );

Memdc1.deletedc ();

}

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.