This project has moved. For the latest updates, please go here.

Can Magick.NET automatically identify image encoding?

Oct 17, 2016 at 7:57 PM
I have files that are usually - but not always - in TGA format. They are named with a .1 extension.

Code like the below fails on the new MagickImage(f) call with a "no delegate" exception when f is, for example, "00001.1"

If I change the file name and value of f to "00001.tga" it works. Is there a way to get Magick.NET to identify the image format regardless of file name extension?
            using (MagickImage image = new MagickImage(f))
                // Convert to .bmp
                image.Format = MagickFormat.Bmp;
                // Create byte array that contains image
                byte[] data = image.ToByteArray();
                File.WriteAllBytes(Path.Combine(ImageFolder, jFolder, s.Replace(".1", ".bmp")), data);
Oct 18, 2016 at 2:15 PM
Edited Oct 18, 2016 at 2:15 PM
Detecting the format works for a lot of image formats but that is not possible for the TGA format. This format has no marker at the beginning that we can use to identify it (see But you can force Magick.NET to read it as a specific format with the MagickReadSettings:
MagickReadSettings settings = new MagickReadSettings()
  Format = MagickFormat.Tga

using (MagickImage image = new MagickImage(f, settings))