c# - 如何获取图像属性?

标签 c# winforms

最重要的属性是图像的高度和宽度,但还需要其他属性。

我试过这段代码:

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/

相关文章:

.net - 是否有 Control.BeginInvoke 的变体可以在句柄销毁之前/之后工作?

c# - 如何在c#中制作多个图像的透明背景

c# - 单个对象创建时的 AutoFixture 自定义

c# - WinForms - 如何获得控件 "wants"的大小?

C# 单例定义

c# - 使用不可选择的项目创建 WinForms ComboBox

c# - Entity Framework 6 自动迁移定期在生产服务器上重建表

c# - 控制更改其他 UserControl 上的控制

c# - 如何使用 WinForms 的现有组件创建类似 Google 的日历

c# - 无法弄清楚计算时间表以在日历上显示日期的例程 - 算法