PNG file with alpha transparency on a transparent form.

JumpyNET

Well-known member
Joined
Apr 4, 2005
Messages
151
In VB2005 it is easy to display a picture with transparency on a totally transparent form. All you have to do is: Set the forms BackColor and TransparencyKey to be the same color plus insert a picturebox and import a transparent picture to it.

But it doesnt seem to work well with PNG files that have alpha transparency. The semitransparent areas arent transparent at all. Is there a way to get this work without having to copy the background from windows and faking transparency on the form?
 
Cags said:
Thanks for the answer but its not what I was looking for. In the thread you gave the link to divil said:
We want to take a source image in 32bpp format (Im using a PNG), a source image taken from the screen (the area behind your splash screen) and perform alpha blending to draw the surface of the layered window.

I asked:
Is there a way to get this work without having to copy the background from windows and faking transparency on the form?
 
The reason you are having this problem is because of the way that the TransparencyKey works. It uses a feature of Windows that allows a region to be specified to customize the shape of the window (make it non-rectangular), but the pixels in a region can only be 100% opaque or 100% transparent. .NET takes pixels that match exactly with the TransparencyKey and exclude them from the region.

Suppose you specify Magenta as your BackColor and your TransparencyKey, then you throw a transparent GIF on the form. The transparent pixels in the GIF will be rendered magenta, the BackColor of the form, then these magenta pixels will be excluded from the Forms region because they match the TransparencyKey, effectively rendering the transparent areas of the GIF as transparent.

Now suppose we have an ARGB PNG. Suppose a pixel is 50% transparent black. It will be rendered at a 50% average between the forms backcolor and black, which will result in dark magenta. Since this doesnt match the TransparencyKey, instead of rendering transparent or semi-transparent, it will render dark magenta.

I dont have the answer to your quesion, only a couple suggestions: It might be possible to create fully alpha-blended windows using layered windows, but Im not sure. I recommend you research this. I also know that WinAmp features certain "modern skins" that implement fully alpha-blended windows. Perhaps you can figure out how this is done. No matter how you do it, if you do it, you will need to go beyond the functionality provided by .Net.
[Edit]I got pretty curious myself, and found this: http://www.thecodeproject.com/cs/media/perpxalpha_sharp.asp[/edit]
 
Last edited by a moderator:
Back
Top