1

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?

Community
  • 1
  • 1
Alejandro Lozdziejski
  • 1,063
  • 4
  • 12
  • 30
  • This is something to do with the transparency of your source image. I just tried it by saving your PNG with a white background and the conversion works fine. I have experimented with the PngBitmapDecoder class but I get the same results, so not sure of the solution as yet. – Gary Wright Feb 02 '15 at 10:32
  • Do you need a program in .net, or is this just for one single conversion with the supplied image? – Jongware Feb 02 '15 at 15:20
  • It's for a script that I'm writing so I a binary I could call from a .net process would do the trick as well – Alejandro Lozdziejski Feb 02 '15 at 16:17

1 Answers1

2

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

Community
  • 1
  • 1
leonbloy
  • 73,180
  • 20
  • 142
  • 190