Embedded resource image is adding a white dot to my image

69 views Asked by At

I have a transparent .png that I'm loading from my assembly. I'm converting this embedded resource to a byte array then to a Bitmap Image, problem is there's always a white dot added to the image,

enter image description here

I'm using the following code,

        using (var stream = this.GetType().Assembly.GetManifestResourceStream("MyProject.test.png"))
        {
            var buffer = new byte[stream.Length];
            stream.Read(buffer, 0, (int)stream.Length);

            return buffer;
        }

This image is straight from https://www.iconfinder.com/ with no modification, I've also tried other images, same effect.

1

There are 1 answers

0
Clemens On

Set the Build Action of the image file to Resource instead of Embedded Resource and then create a BitmapImage like this:

var bitmapImage = new BitmapImage(new Uri("MyProject.test.png", UriKind.Relative));

If you had a file test.png in an Images folder in your project, the Uri would look like this:

var bitmapImage = new BitmapImage(new Uri("Images/test.png", UriKind.Relative));