添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams
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?

While you can always Lock the bitmap and fill it with whatever data you want, I'm not sure what you're trying to accomplish. The RGB channels have no meaning when opacity is 0. I don't know why they're discarded, but it's not surprising. – Esme Povirk Feb 15, 2019 at 4:47

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.

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.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.