Search code examples
vb.nettransparencygradientpictureboxphotoshop

vb transparent background with gradient


I have a problem with gradients transparency key in a PictureBox in visual basic form . I want to get a good transparency as it is in the first form (in PS) That's what I did:

1- Drawed the picture in Adobe Photoshop (CS6) with these preset:

Photoshop preset

2- Saved the picture with this option:

PNG Option

3- Added the picture to a PictureBox in vb form with blue BackColor

PictureBox with blue BackColor

4- Changed form TransparencyKey to blue

TransparencyKey

5-The (awful) result:

Result


Solution

  • The Form.TransparencyKey property is not really what you're looking for. It will only make the parts of the image transparent that exactly match the color you specified (Color.Blue, in your case). That means that the parts of the gradient in your image that have even a remotely small amount of red or yellow in them won't match the filter.

    Among the things you could try is to have your form drawn with alpha blending. Here's a library that lets you draw stuff with transparency, which looks like what you want. Alternately I dug up a walkthrough on CodeProject. It involves a lot of chatting with forms interop and the OS, which might not be your cup of tea.

    Note that GDI+, the system Windows Forms uses for drawing, is somewhat slow, especially when drawing images. I don't know what your project looks like, but if you're going to draw a lot of transparent images, I suggest looking towards Microsoft DirectX.