I have this file types Filters:
public const string Png = "PNG Portable Network Graphics (*.png)|" + "*.png";
public const string Jpg = "JPEG File Interchange Format (*.jpg *.jpeg *jfif)|" + "*.jpg;*.jpeg;*.jfif";
public const string Bmp = "BMP Windows Bitmap (*.bmp)|" + "*.bmp";
public const string Tif = "TIF Tagged Imaged File Format (*.tif *.tiff)|" + "*.tif;*.tiff";
public const string Gif = "GIF Graphics Interchange Format (*.gif)|" + "*.gif";
public const string AllImages = "Image file|" + "*.png; *.jpg; *.jpeg; *.jfif; *.bmp;*.tif; *.tiff; *.gif";
public const string AllFiles = "All files (*.*)" + "|*.*";
static FilesFilters()
{
imagesTypes = new List<string>();
imagesTypes.Add(Png);
imagesTypes.Add(Jpg);
imagesTypes.Add(Bmp);
imagesTypes.Add(Tif);
imagesTypes.Add(Gif);
}
OBS: Is there any default filters in .NET or a free library for that?
I need a static method that checks if a string is an image or not. How would you solve this?
//ext == Path.GetExtension(yourpath)
public static bool IsImageExtension(string ext)
{
return (ext == ".bmp" || .... etc etc...)
}
Solution using Jeroen Vannevel EndsWith. I think it is ok.
public static bool IsImageExtension(string ext)
{
return imagesTypes.Contains(ext);
}