Transparent background, blending

Started by
2 comments, last by phil_t 11 years, 7 months ago
Hi guys. I'm not really experienced with graphics, and been having some issues. I have a couple of textures that have black backgrounds, but some of the actual texture is kind of transparent and shows a bit of the black behind it. This way, when I try to set ColorKey to black, it just fails to get the whole thing transparent.

I would like to know if there's a drawing technique in which the different tones of black on the image would be removed and set as transparent. I'm not really sure if I'm being clear enough, so sorry about that.

This is a sample image:

status8.png
Advertisement
I'm not sure I understood your issue (the image didn't really help), but it seems to me like what you are looking for is alpha channel. With ColorKey you can have only a single color set as transparent, if you set it to 0,0,0 (black) then ONLY perfectly black pixels will be transparent. With alpha channel you can control the transparency with great flexibility.
The most common texture formats with alpha channel are PNG and TGA.
What I'm talking about is, I got an image like that one, and I want to turn black into transparent. That simple. I understood that ColorKey is used when you have rough edges and no transparency on the image, so you only need to remove exact color matches.

You mean that to obtain transparency on an image such as that one, I will have to edit the image, and not do it through XNA?

(even thought I still haven't found a way to change that black background efficiently on Adobe Fireworks)

# Well, actually now I found a way to do this efficiently on Fireworks X.X

Selecting the image, Inverting the colors so the background is white. Adding Convert to Alpha filter on the image so white is now alpha. Flatenning the image and then Inverting colors once again, to get transparent background.

I just couldn't find a way around this on the image editor before and decided to ask here for ways to do it by code.
I think you could achieve this by drawing the proper BlendState. Something like this:

BlendState bs = new BlendState()
{
ColorSourceBlend = Blend.SourceColor,
ColorDestinationBlend = Blend.InverseSourceColor,
};

This topic is closed to new replies.

Advertisement