Question Transparent Background

Lep255

Member
Joined
Apr 3, 2022
Messages
7
Programming Experience
Beginner
I'm trying to make use of the Transparency feature to make a better looking form... issues is that, the background is disgusting. I took a picture of an example(the white behind the black smudge), is there a way to get rid of that? I've tried to look around so much but tbh... I don't even know what that's called.

Screenshot 2022-04-18 235921.png
 
Show us the code you use "to make use of the Transparency feature".

Right now, it looks like those white sections are artifacts of the algorithm you used to determine which pixels should be the transparent pixels. It almost looks like the effects of an edge tracing algorithm.
 
The image shouldn't have traces of anything other than black. Still learning, didn't think I had to add more code to it, thought it was an issue with the properties. Could you redirect me to somewhere that can give me more information or explain how I can work on this type of issue? I couldn't find anything that seemed remotely helpful aside from other variations of the same code I'm using:
C#:
this.TransparencyKey = BackColor;
 
Is this a WinForms program?
 
Moving to WinForms...

Okay, and what is the current value of BackColor?

And can you also please upload a copy of that image (.png, .jpeg, or .bmp) that you are using.

What I am suspecting is that those whitish artifacts are actually part of the image but a slightly different RGB color from your selected BackColor. They are actually some off-white color. Artists will often use a slight color variation to do anti-aliasing to make edges less laggy. When in the original image they are adjacent to the actual white color. Later when your tell WinForms to use the white color as the transparency key, WinForms goes and masks out all the white, but leaves the off-white color behind.
 
Last edited:
Moving to WinForms...

Okay, and what is the current value of BackColor?

And can you also please upload a copy of that image (.png, .jpeg, or .bmp) that you are using.

What I am suspecting is that those whitish artifacts are actually part of the image but a slightly different RGB color from your selected BackColor. They are actually some off-white color. Artists will often use a slight color variation to do anti-aliasing to make edges less laggy. When in the original image they are adjacent to the actual white color. Later when your tell WinForms to use the white color as the transparency key, WinForms goes and masks out all the white, but leaves the off-white color behind.
That’s actually just a random image I had lying around. But I’ve already gone ahead and grabbed a fresh image from photoshop that I made with a brush. I’ve changed the backcolor to Lime, Magenta, White, Black, Gold and it all gives the same result. I’ve only found one project that seems to get things to work correctly, I currently have the source code of it, but the method they used to get it to work seems inefficient. I’m not near my computer at the moment, but what they did was create 2 separate forms one for the code and one for the image. Tomorrow I’ll be able to explain with better information at hand.
 
Please post one of those images. PhotoShop also performs that anti-aliasing to give smooth transitions.

As for the alternate way, that is the standard approach for pre-GDI+ (and therefore pre-WinForms since WinForms uses GDI+) code where there was no transparency key to offload the work to GDI+.
 
Also as a quick aside, read closely about the what the TransparencyKey does:

What effectively happens is that you have "holes" in your form so that you see the windows that are underneath your form. It's unclear to me how this will make a better looking form since based on your screenshot above, you'll now have a big gaping hole in the middle of your form.
 

Latest posts

Back
Top Bottom