Accord.Imaging.Tools.GetFormat C# (CSharp) Method

GetFormat() public static method

Gets the image format most likely associated with a given file name.
public static GetFormat ( string fileName ) : ImageFormat
fileName string The filename in the form "image.jpg".
return System.Drawing.Imaging.ImageFormat
        public static ImageFormat GetFormat(string fileName)
        {
            string extension = Path.GetExtension(fileName);

            if (string.IsNullOrEmpty(extension))
                throw new ArgumentException("Unable to determine file extension for fileName: " + fileName);

            switch (extension.ToUpperInvariant())
            {
                case @".BMP":
                    return ImageFormat.Bmp;

                case @".GIF":
                    return ImageFormat.Gif;

                case @".ICO":
                    return ImageFormat.Icon;

                case @".JPG":
                case @".JPEG":
                    return ImageFormat.Jpeg;

                case @".PNG":
                    return ImageFormat.Png;

                case @".TIF":
                case @".TIFF":
                    return ImageFormat.Tiff;

                case @".WMF":
                    return ImageFormat.Wmf;

                case @".EMF":
                    return ImageFormat.Emf;

                default:
                    throw new NotImplementedException();
            }
        }
    }