Ich habe diese Dateitypen Filters:gute Möglichkeit zu überprüfen, ob Dateierweiterung eines Bildes ist oder nicht
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: Gibt es eine Standardfilter in .NET oder eine freie Bibliothek für das?
Ich brauche eine statische Methode, die überprüft, ob eine Zeichenfolge ein Bild ist oder nicht. Wie würdest du das lösen?
//ext == Path.GetExtension(yourpath)
public static bool IsImageExtension(string ext)
{
return (ext == ".bmp" || .... etc etc...)
}
Lösung mit Jeroen Vannevel EndsWith. Ich denke es ist ok.
public static bool IsImageExtension(string ext)
{
return imagesTypes.Contains(ext);
}
Vielleicht wollen Sie auch [MIME-Typ Erkennung] tun es zu prüfen, durch (http://stackoverflow.com/questions/15300567/ alternative-to-findmimefromdata-methode-in-urlmon-dll-one-die-hat-mehr-mime-type), es ist mehr "vertrauenswürdig", dass die Dateierweiterung, –