views:

219

answers:

1

Hello, I found that using BmpBitmapEncoder to render any type of image works, the only thing I'd need to do is send the correct format in the file to be saved as in the following example:

BmpBitmapEncoder encoder = new BmpBitmapEncoder();;

encoder.Frames.Add(BitmapFrame.Create(renderer));
using (System.IO.FileStream fs = System.IO.File.Open("file.png", System.IO.FileMode.OpenOrCreate))
{
    encoder.Save(fs);
}

So, as you can see, the name of the image is "file.png", and this works correctly, it saves the image as PNG (also works with jpeg, tiff, gif), and it can be loaded with any image processing application.

I just want to know how is this different from using the correct encoder for each type (PngBitmapEncoder, JpegBitmapEncoder, GifBitmapEncoder, etc) instead.

Thank you.

+2  A: 

You MUST use the right encoder PngBitmapEncoder, JpegBitmapEncoder, GifBitmapEncoder.

The file you are saving this way is ALWAYS a BMP!

What is happening in your test is that the image processing application you are using is ignoring the extension and recognizing the real file format as a BMP.

tekBlues
Oh this makes sense, I actually did some extension recognition logic to select the correct converter, I was just wondering what the difference was.Thanks!
Carlo