我有这个文件类型过滤器:
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:.NET 中是否有任何默认过滤器或免费库?
我需要一个静态方法来检查字符串是否是图像。你会如何解决这个问题?
//ext == Path.GetExtension(yourpath)
public static bool IsImageExtension(string ext)
{
return (ext == ".bmp" || .... etc etc...)
}
使用 Jeroen Vannevel EndsWith 的解决方案。我认为没关系。
public static bool IsImageExtension(string ext)
{
return imagesTypes.Contains(ext);
}