最重要的属性是图像的高度和宽度,但还需要其他属性。
我试过这段代码:
private void getImageProperties()
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.ShowDialog();
Dictionary<int, KeyValuePair<string, string>> fileProps =
GetFileProps(openFileDialog.FileName);
foreach (KeyValuePair<int, KeyValuePair<string, string>> kv in fileProps)
Console.WriteLine(kv.ToString());
}
但是什么是 GetFileProps
?它不存在。
最佳答案
这是 GetFileProps
:
Dictionary<int, KeyValuePair<string, string>> GetFileProps(string filename)
{
Shell shl = new ShellClass();
Folder fldr = shl.NameSpace(Path.GetDirectoryName(filename));
FolderItem itm = fldr.ParseName(Path.GetFileName(filename));
Dictionary<int, KeyValuePair<string, string>> fileProps = new Dictionary<int, KeyValuePair<string, string>>();
for (int i = 0; i < 100; i++)
{
string propValue = fldr.GetDetailsOf(itm, i);
if (propValue != "")
{
fileProps.Add(i, new KeyValuePair<string, string>(fldr.GetDetailsOf(null, i), propValue));
}
}
return fileProps;
}
但这需要添加一些引用。更多信息请查看this forum从我复制方法的地方。请开始使用 Google!
关于c# - 如何获取图像属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18833594/