GDI+ resets color of transparent part of image to black

0

Ho do I draw a specific transparent color with GDI+ ?

I tried this code:

m_image = new Gdiplus::Bitmap( img_w, img_h );
m_graphic = Gdiplus::Graphics::FromImage( m_image );

Gdiplus::Color c( 0, 255, 0, 0 ); // ARGB = 0x00FF0000

m_graphic->Clear( c );

m_image->GetPixel( 0, 0, &c ); //ARGB = 0x00000000 ?!

The color of transparent part of the image is always black. How can I change this?

gdi+
asked on Stack Overflow Feb 14, 2019 by Tim Thaller

1 Answer

2

The Graphics::Clear method clears a Graphicsobject to a specified color. I have tried your code:

Image m_image(L"C:\\Users\\strives\\Desktop\\apple.jpg");
Graphics *m_graphic = Graphics::FromImage(&m_image);
Gdiplus::Color c(0, 255, 0, 0); // ARGB = 0x00FF0000
m_graphic->Clear(c);
graphics.DrawImage(&m_image, 30, 20);
delete m_graphic;

The final picture is like this.

enter image description here

I think the problem is clear. If you use the clear function and set the color to (0, 255, 0, 0), which defaults to black, then the printed area must be black, and the color of the pixels captured by the GetPixel function below you must be black.

answered on Stack Overflow Mar 1, 2019 by Strive Sun - MSFT • edited Dec 17, 2020 by Strive Sun - MSFT

User contributions licensed under CC BY-SA 3.0