PNG Alpha blending/channel in VC++ 6.0?
-
Hi All, I am writing an application which try to show PNG file as a dialog background using GDI+ I have successfully using the PNG as background (using
Graphics::DrawImage()
), however, I found that the loaded PNG seems not apply the alpha channel information. What I should do? Thanks! (sorry for repeat posting if there is any) Vincent -
Hi All, I am writing an application which try to show PNG file as a dialog background using GDI+ I have successfully using the PNG as background (using
Graphics::DrawImage()
), however, I found that the loaded PNG seems not apply the alpha channel information. What I should do? Thanks! (sorry for repeat posting if there is any) VincentWhere in your code are you calling DrawImage()? What is the background behind the image and how is it drawn? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Where in your code are you calling DrawImage()? What is the background behind the image and how is it drawn? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
I called it at OnEraseBackground() I would like to have a transparent background (i.e. I set the desktop background to black/white, I hope the image boundary will be "blur" with the work of alpha bending). I am not sure if what I do is right, however, with using the
Graphics::SetCompositingMode()
, it seems that theGraphics::DrawImage()
method will not directly apply the alpha bending information? ( I useBitmap::GetPixelFormat()
to verify the input image is a PixelFormat32bppARGB type, which means it should include the alpha channel) -
I called it at OnEraseBackground() I would like to have a transparent background (i.e. I set the desktop background to black/white, I hope the image boundary will be "blur" with the work of alpha bending). I am not sure if what I do is right, however, with using the
Graphics::SetCompositingMode()
, it seems that theGraphics::DrawImage()
method will not directly apply the alpha bending information? ( I useBitmap::GetPixelFormat()
to verify the input image is a PixelFormat32bppARGB type, which means it should include the alpha channel)You shouldn't need much more than this...
// Load a bitmap
Bitmap SrcBitmap(L"C:\\Test.png", FALSE);
...
// Draw the bitmap to the DC at 0,0
Graphics DstGraphics(hdc);
DstGraphics.SetCompositingMode(CompositingModeSourceOver);
DstGraphics.DrawImage(&SrcBitmap, 0, 0, SrcBitmap.GetWidth(), SrcBitmap.GetHeight());If something's not working I'd have to see a code sample to possibly help :) Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
You shouldn't need much more than this...
// Load a bitmap
Bitmap SrcBitmap(L"C:\\Test.png", FALSE);
...
// Draw the bitmap to the DC at 0,0
Graphics DstGraphics(hdc);
DstGraphics.SetCompositingMode(CompositingModeSourceOver);
DstGraphics.DrawImage(&SrcBitmap, 0, 0, SrcBitmap.GetWidth(), SrcBitmap.GetHeight());If something's not working I'd have to see a code sample to possibly help :) Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
Hi Mark, Thanks for your reply ^^ err... what I wrote right now is exactly same as yours... (even the file name ) however, the outcome is just a dark background but not transparent... Maybe I put at a wrong message call location? I put the above code under OnEraseBackground() Vincent
-
Hi Mark, Thanks for your reply ^^ err... what I wrote right now is exactly same as yours... (even the file name ) however, the outcome is just a dark background but not transparent... Maybe I put at a wrong message call location? I put the above code under OnEraseBackground() Vincent
Hmm...do you have a sample of a png image that isn't working that you can send me to test? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: