This code below solves this problem. It uses the MIME types that are configured for the PC, as defined in the Windows Registry. Nice and simple solution.
public static string GetImageFormatsFileFilter()
{
string retVal= "*" + string.Join(";*", SupportedImageFormats());
return retVal;
}
public static string[] SupportedImageFormats()
{
List retVal = new List();
RegistryKey BaseKey = Registry.ClassesRoot.OpenSubKey("MIME").OpenSubKey("Database").OpenSubKey("Content Type");
foreach (string subkey in BaseKey.GetSubKeyNames())
{
if (subkey.ToUpperInvariant().StartsWith("IMAGE/"))
{
string ext = (string)BaseKey.OpenSubKey(subkey).GetValue("Extension");
if (ext != null && !retVal.Contains(ext.ToUpperInvariant()))
{
retVal.Add(ext.ToUpperInvariant());
}
}
}
return retVal.ToArray();
}
No comments:
Post a Comment