Use GDI + to convert a 24-Bit Bitmap to a 32-Bit Bitmap

Source: Internet
Author: User

Today, the alpha channel of the modified image is used to implement the image reflection. However, when we test the image, we find that the 24-Bit Bitmap cannot implement the reflection, the reason is that there is no alpha channel for images with less than 24 digits, and there is no way to modify the alpha channel to implement image reflection. So I want to convert a 24-bit image into a 32-bit image. It can also have an alpha channel. In this case, some features of GDI + are used. Share the program.

Bool getbitmapdata (Bitmap * pbitmap, pixelformat, bitmapdata * Data)
{
Bitmap * BMP = pbitmap;
Gdiplus: rect R (0, 0, BMP-> getwidth (), BMP-> getheight ());
Uint pixelsize = getpixelformatsize (pixelformat );
Data-> stride = (pixelsize * R. Width + 31) & 0xffffffe0)> 3;
Data-> scan0 = (void *) New char [R. Height * Data-> stride];
BMP-> lockbits (& R, imagelockmoderead | imagelockmodeuserinputbuf,
Pixelformat, data );
BMP-> unlockbits (data );
// Delete BMP;
Return true;
}
// The pbitmap parameter is a 24-Bit Bitmap for transmitting objects.

Void change24to32 (Bitmap * pbitmap)
{
Bitmapdata data;
If (! Getbitmapdata (pbitmap, pixelformat32bppargb, & Data ))
Return;
If (pbitmap)
Delete pbitmap;
// Create a user-defined data bitmap object in 24-bit pixel format
Bitmap * BMP = new Bitmap (data. Width, Data. Height, Data. stride,
Data. pixelformat, (byte *) data. scan0 );
Pbitmap = BMP; // assign a new bitmap value to the transmitter.
}

 

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.