Sign in to follow this  
arthurviolence

Transparent background, blending

Recommended Posts

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:

[img]http://imageshack.us/a/img42/9008/status8.png[/img]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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. Edited by Arthur Souza

Share this post


Link to post
Share on other sites
I think you could achieve this by drawing the proper BlendState. Something like this:

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this