Search code examples
c#graphicsxnaantialiasing

XNA No 2D anti-aliasing when using Texture2D.FromStream


i have looked around quite a bit and have not found a working solution for rendering 2D textures with anti-aliasing. I have this image;

enter image description here

when i render it using XNA i get the results on the left. when i render it with Flash, a browser or a graphics proggy i get the results on the right.

enter image description here

i have searched and the suggestion has always bee to change the settings in the GraphicsDevice but i cannot seem to get this to work. Could anyone give me a working example of anti aliasing (possibly using the image provided).

Thank you so much for your help. I really do appreciate it.


Solution

  • When processing hundreds of images from different sources not in your game, you can load them with Texture2D.FromStream as you do now. This doesn't handle alpha very well.

    I was going to dive into my game's source to look at how I did it when I stumbled upon this post from GameDev.SE which gives some options to solve the issue, and an illustration on what is happening:

    https://i.sstatic.net/UBu9Y.jpg

    While option #1 is faster, I would go with #2, it may look very complex at first but I have tried it and it works very well.

    Now if you ever happen to have an issue with antialiasing, or want to enable/disable it, you can do so: graphics.PreferMultiSampling = true;