GDI +将图像透明部分的颜色重置为黑色

问题描述 投票:0回答:1

何我用GDI +绘制特定的透明色?

我试过这段代码:

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 ?!

图像透明部分的颜色始终为黑色。我怎么能改变这个?

gdi+
1个回答
2
投票

Graphics :: Clear方法将Graphicsobject清除为指定的颜色。我试过你的代码:

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;

最后的图片是这样的。

enter image description here

我认为问题很明显。如果使用清除功能并将颜色设置为(0,255,0,0)(默认为黑色),则打印区域必须为黑色,并且下方的GetPixel函数捕获的像素颜色必须为黑色。

© www.soinside.com 2019 - 2024. All rights reserved.