public static ImageFormat GetImageFormat(string filePath) { ImageFormat imageFormat = ImageFormat.Png; string ext = Helpers.GetFilenameExtension(filePath); if (!string.IsNullOrEmpty(ext)) { switch (ext) { default: case "png": imageFormat = ImageFormat.Png; break; case "jpg": case "jpeg": case "jpe": case "jfif": imageFormat = ImageFormat.Jpeg; break; case "gif": imageFormat = ImageFormat.Gif; break; case "bmp": imageFormat = ImageFormat.Bmp; break; case "tif": case "tiff": imageFormat = ImageFormat.Tiff; break; } } return(imageFormat); }