Click here to Skip to main content
14,211,925 members
Rate this:
Please Sign up or sign in to vote.
Hello,

I have some code that uses GDI+ to convert an icon to grayscale*. However, when transparency (i.e. alpha channel) is involved, the resulting icon seems to use pre-multiplied alpha - rather than normal alpha - making the transparent pixels look darker.


* Create GDI+ Bitmap from HICON, create blank Bitmap, draw icon bitmap onto new bitmap using a colour matrix, convert new bitmap to HICON.

What I have tried:

I found that when drawing to the screen using GDI+ Graphics class, it looks ok. It's only when converting back to an icon using Bitmap::GetHICON that the problem occurs. Which leads me to believe that the GetHICON function is implicitly converting the image to pre-multiplied alpha.

It does not seem to matter whether I use PixelFormat32bppARGB or PixelFormat32bppPARGB at any point, as I get the same effect.
Posted
Updated 18-Nov-18 18:34pm
v2
Comments
Aydin Homay 19-Nov-18 3:24am
   
Please post your code and explain on the code what you are trying to do
XTAL256 20-Nov-18 17:42pm
   
The code is quite complex, and it will be hard to make a simple example to demonstrate my problem.

However, since you prompted me to look at the code again, I think I see what the problem is. The code that converts HICON to GDI+ Bitmap tries to do some tricky stuff with the alpha channel of 32-bpp icons.

Specifically, my code is calling Bitmap::FromHBITMAP and passing the icon's colour bitmap (obtained from GetIconInfo). It then copies the pixel data to the GDI+ bitmap.
If I call Bitmap::FromHICON instead, then the 8-bit alpha channel is not preserved and the 1-bit mask is used instead.

I will investigate that code further.
Michael Haephrati 18-May-19 9:34am
   
I think you should call SetColorKey with the correct transparency

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190619.2 | Last Updated 19 Nov 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100