Carlo
Carlo

Reputation: 25969

Using BmpBitmapEncoder for all image formats

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.

Upvotes: 1

Views: 2657

Answers (1)

tekBlues
tekBlues

Reputation: 5793

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.

Upvotes: 3

Related Questions