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();
}
}
}