C # - Winforms transparency issue (I'm going crazy)

I will show you the image below, but before that ...

if you saw yahoo widgets or cartoony / themed windows media player skins ..

I create a less header ... background less ... application ... it looks like this

alt text http://fc05.deviantart.net/fs70/f/2010/212/4/c/scrap_by_junaid_saeed.jpg

the dark background that you see is actually my wallpaper because it is a screenshot ...

to achieve this .. body shapes and lines, I use Trasparent PNG .. then I use the Win shape transparency key to make it transparent .. and the image is loaded into the image window ...

My problem is the white dots that you see throughout the body. This is due to the fact that pixels of this PNG that are not completely opaque or transparent, i.e. translucent ... so the transparency key cannot make the background shape transparent in these pixels ... and you see these white dots ...

well is there any other way to make the form transparent, because ...

  • the transparent key will always behave this way, because no matter what you do, these translucent pixels of the image on the curves will always be ...
+4
source share
2 answers

Johannes mentioned major issues with your current approach.

You can create alpha blending in Windows Forms, but you will need to use the Windows API call (among others): UpdateLayeredWindow .

Visual C # kicks has a useful tutorial and source code on how to do this to create a professional looking screensaver.

The only drawback is that if your form contains child controls, such as buttons, text fields, they will not be drawn using UpdateLayeredWindow. However, you could simulate buttons, etc., by manually drawing them as part of the background of the form.

+2
source

Your problems are here

  • PNG is smoothed
  • It is composed against the background of the usual form (SystemColors.Control)
  • If you make it transparent using the TransparencyKey property (which makes one color transparent, but nothing more), you will get opacity, where PNG has partial transparency.

So far so expected. Keep in mind: you are not drawing partially transparent PNG on the screen; you draw it on your shape, and then take the final result and make one color transparent. For all that it costs, your PNG could have been pink as the surrounding color, the result would be the same.

You can look at the regions or not smooth the PNG that you draw.

+3
source

All Articles