Jump to content
  • Advertisement
Sign in to follow this  
Jeffsg605

Loading in transparent image

This topic is 2268 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello guys, I am making a tile map editor and I am using windows forms to load in files. When I load in a texture the magenta does not show up transparent. I realize this is normal but how do I go about making it transparent. I am loosely following this video:

At 7:30, you can see he uses something like TextureCreationParameters to do this. However that was in an older version of XNA. Does anybody know how to do this for XNA 4.0?

Thanks a lot!

Share this post


Link to post
Share on other sites
Advertisement
Nevermind figured it out. Three days of searching led to no result. Ten minutes after I make a post I figure it out. If anyone is curious, do this

FileStream fs = new FileStream(filename, FileMode.Open);
Texture2D texture = Texture2D.FromStream(Game1.graphics.GraphicsDevice, fs);
Color[] data = new Color[texture.Width * texture.Height];
texture.GetData<Color>(data, 0, data.Length);
for (int i = 0; i < data.Length; i++)
{
if (data.R == 255 && data.G == 0 && data.B == 255)
{
data = new Color(255, 255, 255) * 0f;
}
}
texture.SetData<Color>(data, 0, data.Length);
fs.Close();

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!