|
-
Mar 29th, 2014, 11:37 AM
#1
Thread Starter
New Member
Transparency Issues
Greetings, well I've made a border less form, with the transparency and backcolor the same colors. I've set a panel and gives it a transparent background image, the outline of the image is pixelated from the color of the transparency key, any ideas of what might be happening? Thanks in advance.
-
Apr 2nd, 2014, 01:22 AM
#2
Member
Re: Transparency Issues
same problem i'm facing right now. according to what i found on the forum it looks like you can avoid this by using a WPF project which i do not want to use... hopefully there's some trick to make this work on a "normal" project either...
-
Apr 2nd, 2014, 07:31 AM
#3
Re: Transparency Issues
The problem is that Windows Forms can't alpha-blend individual pixels. That means you can only vary the transparency of the whole form with the Opacity property, or make smaller areas totally transparent either with the TransparencyKey property or the Region property.
The pixels you see around the edge of an image in the TransparencyKey are pixels that are partly but not wholly transparent. That means their colour is not exactly the same as the TransparencyKey (even if you can't see the difference) so they won't turn transparent. Those partly transparent pixels may be the result of drawing an image with anti-aliasing into a transparent background, or by using a feathering tool, in a painting program. Anyway the anti-aliasing pixels won't be transparent on a Windows Form. In short, Forms can't do anti-aliasing against the desktop.
There are three ways to deal with this:
1. Clean up your image in a painting program by erasing the partly transparent pixels. But that means losing any anti-aliasing or feathering. At least you won't see those pixels in the TransparencyKey color, though curves and diagonal edges may look a little rough.
2. Do a screen grab of the area behind the panel or the whole form and use that as a background image. You could paint your image with partly transparent pixels onto that -- or paint both images together -- in the control's Paint event. The snag of this is that you have to hide the image while you do the screen grab. So it's only practical if the Form is not going to move or resize. Momentarily hiding the image to do a new screen grab looks messy because of the flashing. An exception to this is to make the form 99% opaque and do the screen grab with CopyFromScreen, which is blind to anything less than 100% opaque -- but only in Windows XP, not in Vista or later.
3. Use a display technology that allows per-pixel alpha blending. You can turn a form into a Layered Window by setting certain bits in CreateParams. I wont go into details because it requires some complicated Win32 apis and the result can't host controls or do a lot of other Forms things. If you are going to go that far, you might as well go straight to WPF, which uses Layered Windows under the hood somewhere. It depends on your design, but it may not be as hard as you think to incorporate a WPF Window into a Windows Forms project. See the "shaped form" link in my signature for a step by step description of how you could do this even if you know next to nothing about WPF.
BB
-
Apr 2nd, 2014, 08:34 AM
#4
Member
Re: Transparency Issues
if there is no other way but using the WPF, i'll go for it, i just didnt want to use it because my project is still using framework 2.0 and i can add a WPF starting from the 3.0.
thank you very much as always
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|