I'm writing a program to convert one image type (for example, png or gif, or tif) to a jpg. What I want to do is to feed the file name into the program via the console, and it will spit out the converted image. How can I make sure that the file given in the argument is of the correct type? Preferably I'd like to have it do more than just check the extension, because that could be erroneous.
This is my code as it stands.
Stream imageStreamSource = new FileStream("image.png", FileMode.Open, FileAccess.Read, FileShare.Read);
PngBitmapDecoder decoder = new PngBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource bitmapSource = decoder.Frames[0];
FileStream stream = new FileStream("new.jpg", FileMode.Create);
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
Console.WriteLine(decoder.CodecInfo.MimeTypes.ToString());
Console.WriteLine(encoder.CodecInfo.MimeTypes.ToString());
encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
encoder.Save(stream);