2016-03-15 38 views
-1

我有图像(JPG,GIF,PNG等)本地硬盘。我需要读取所有文件信息,例如位置详细信息纬度经度或位置名称和照片创建日期每个图像。请帮助我如何阅读位置详细信息和日期。C#镜像文件信息读取位置的详细信息和日期

这是我的C#代码是不显示位置的信息或创建日期

string directory = (@"C:\Photos"); 
var AllImages = Directory.GetFiles(directory, "*.jpg", 
            SearchOption.AllDirectories) 
         .Select(Image.FromFile).ToList() 

这是我的照片例子

之一。 enter image description here

+0

https://msdn.microsoft.com/en-us/library/xddt0dz7.aspx CodeProject上也有一些库。你想要的术语是'EXIF' – Plutonix

回答

1

您正在查找的关键字是图片元数据,或者EXIF data。您可以从Image.PropertyItems属性读取原始数据并手动解析它,也可以使用外部库为您完成工作。

我推荐ExifLib - 这是一个非常基本但能够读取EXIF数据的库。这里有一个例子:

// Instantiate the reader 
using (ExifReader reader = new ExifReader(@"C:\temp\testImage.jpg")) 
{ 
    // Extract the tag data using the ExifTags enumeration 
    DateTime datePictureTaken; 
    if (reader.GetTagValue<DateTime>(ExifTags.DateTimeDigitized, out datePictureTaken)) 
    { 
     // Do whatever is required with the extracted information 
     MessageBox.Show(this, string.Format("The picture was taken on {0}", 
      datePictureTaken), "Image information", MessageBoxButtons.OK); 
    } 
} 
+0

我使用visual studio 2015,我是否安装软件包ExifLib。另外我需要读取所有图像文件夹。例如C:\ Photos – Rob

+0

另外检查出[元数据提​​取器](https://github.com/drewnoakes/metadata-extractor-dotnet)。 –