Search code examples
.netimagepngbmp

How can I transform a PNG to a BMP without loosing quality


This is a tricky one. First tried this with an awful result

Image Dummy = Image.FromFile("image.png");   
Dummy.Save("image.bmp", ImageFormat.Bmp);

enter image description here -----transforms into---->enter image description here

I have no idea what could be happening. Any clues?


Solution

  • Both BMP and PNG are lossless, but PNG supports transparency while BMP doesn't. Because your original image has transparency, before converting it you should first ask yourself what you want to happen with the (semi)transparent pixels, and don't let the BMP encoder decide (it seems to take some weird decisions, BTW).

    To remove the transparency amounts, conceptually, to add some opaque background (white or black, normally - in your case, white). For doing that in C#, see this question