I have an image in a PictureBox and have made it transparent by removing the color I don't want. I would now like to soften the edges of the remaining transparent image. Any ideas on how to do so?
Printable View
I have an image in a PictureBox and have made it transparent by removing the color I don't want. I would now like to soften the edges of the remaining transparent image. Any ideas on how to do so?
Not really possible without a ton of work/workarounds, I would think.
You are using regions to shape the picturebox, correct? Shaped child windows don't support semi-transparency/soft edges, but are supported on top-level windows via the UpdateLayeredWindow API. The option to use that API on child windows was introduced in Windows 8. The closest I think you can come to this with using child controls would be something similar to how XP+ softened their edges on some controls. They actually render themselves with a bit of a buffer/reserved space along the edges, and ask the parent window (i.e., the form or whatever) to draw the overlapped portion into the control's reserved space. Now the control can draw itself blended onto what the parent drew.
Edited: This is not so simple to do manually. Suggestions follow:
- Assumption: no animation is occurring wherever the edges of this picbox would end up
- You'll need a screen capture of your form without the picbox in the capture
- Your picbox should be sized slightly larger (by a couple pixels) than the image it's shape was created from
- When you place the picbox, paint the capture to the form to the picbox (or offscreen buffer) using the appropriate offset so what is painted would align up perfectly to the form.
- Now you can use GDI+ or other blending routines to alpha-blend the picbox's image over the buffered screen capture & then that painted onto the picbox.
- The overall effect would be similar to Windows themed controls. In fact, if done this way, you wouldn't even need to shape the picbox to begin with
See how i did here.