All of my png files have a white background instead of transparent

I am sorry if this question has been answered before, but I searched this forum. I searched the web, and I haven’t found any fix. I know what the solution is supposed to be, but it’s not working. Even the png fiiles used in examples such as [these][1] are showing solid instead of transparent.

Here is my code, which is just the beginning:

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Game1_WindowsPhone8xaml
    /// <summary>
    /// This is the main type for your game.
    /// </summary>
    public class Game1 : Game
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        // my Sprites
        Texture2D myButton_START;

        // Set the coordinates to draw the sprite at
        Vector2 myButtonPos = Vector2.Zero;

        public Game1()
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  
        /// The Initialize method is where you can initialize any assets that do not require a 
        /// GraphicsDevice to be initialized.
        /// Calling base.Initialize will enumerate through any components and initialize 
        /// them as well.
        /// </summary>
        protected override void Initialize()
            // TODO: Add your initialization logic here


        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// The LoadContent method is where you load any necessary game assets 
        /// such as models and textures.
        /// </summary>
        protected override void LoadContent()
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // use this.Content to load your game content here
            myButton_START = Content.Load<Texture2D>("earth");

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// game-specific content.
        /// The UnloadContent method is where any game assets can be released. 
        /// Generally, no extra code is required here, as assets will be released 
        /// automatically when they are no longer needed.
        /// </summary>
        protected override void UnloadContent()
            // TODO: Unload any non ContentManager content here

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// The Update loop is the best place to update your game logic.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
            // TODO: Add your update logic here


        /// <summary>
        /// This is called when the game should draw itself.
        /// The Draw loop is the best place to render all of your objects and backgrounds on 
        /// the screen.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
            GraphicsDevice.Clear(Color.Black); // start with a black background 

            // Add your drawing code here
            // Draw the button sprite.
            /// </summary>
            /// Begins a sprite batch operation using the specified sort and blend state object 
            /// and default state objects (DepthStencilState.None, SamplerState.LinearClamp, 
            /// RasterizerState.CullCounterClockwise). If you pass a null blend state, 
            /// the default is BlendState.AlphaBlend.
            /// This method must be called before any calls to Draw. When all the sprites have 
            /// been drawn, call End.
            /// </summary>
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
            spriteBatch.Draw(myButton_START, myButtonPos, Color.White);


Here is what I get

…from this

Hope someone can help. I am only just beginning, and I am stuck.

The original earth.png from the link above has a transparent background. But the image that you have embedded at the end of the post has a white background without transparency. Are you sure you are using the same files?

It shows as a white background as a file. In an image editor, it shows as a transparent image. You can try downloading the image from the link I provides, to test it.

This image is .png but not is transparent. Your image may have a white background.
Edit your image. =)

Is the converted to xnb using the content pipeline tool? If so, we will need to investigate further. Of it is included as a PNG in the project, it will be not be using pre-multiplied alpha. In this case, you should be using BlendState.NonPremultiplied in your SpriteBatch.Begin call.

1 Like

Something is definitely wrong on my system then. Could someone send me a png file with transparency. If I test it, and get the same result, I’ll have to try and figure out what is wrong with my Visual Studio and Mono, because I used the same png images in two other game engines, and they both render them correctly.

I get the same result with and without the content pipeline tool. There is no change with BlendState.NonPremultiplied.

OK. Still send the image. There seems to be a problem with my image editor and png files. When I export a png directly from Inkscape, it is fine. However, if I edit it with my image editor (I use PhotoPlus) and export it, I get the problem. So the image is changed. I’ll have to use Inkscape entirely. I still can’t figure out why the earth image changed though. I downloaded it, and directly imported into the content folder. I’ll have to look into this, cause I never encountered the problem before. Thanks all.

[quote=“Jillinger, post:7, topic:2560”]
However, if I edit it with my image editor (I use PhotoPlus) and export it, I get the problem.
[/quote]I’m going to guess that PhotoPlus doesn’t keep the alpha channel because photos generally don’t require an alpha channel, and from the name it sounds like photo editing is its primary job. Try another image editor, not a photo editor, such as Paint.NET, Pixelformer (great for viewing and editing alpha channel and RGB channels separately), Photoshop (if your budget extends to that) or Gimp (click Show other downloads and keep scrolling down).

No. PhotoPlus is just as good as the best editors out there. The free edition is limited, but it gets the job done well. Actually, I found the problem. PhotoPlus, by default, exports 24bit png files. I had to optimize it to 32bit. Now it works.

Finally, I can move on. Thanks for the responses.