调用的时候如下;ALLNAME是照片的绝对路径...如果返回值为"N/A"说明照片不存在拍摄时间足够属性没有取到
string time = GetTakePicDateTime(GetExifProperties(AllName));
//下面是完整的代码
public static PropertyItem[] GetExifProperties(string fileName)
{
FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
//通过指定的数据流来创建Image
System.Drawing.Image image = System.Drawing.Image.FromStream(stream, true, false);
PropertyItem[] r = image.PropertyItems;
stream.Close();
return r;
}
private string GetTakePicDateTime(System.Drawing.Imaging.PropertyItem[] parr)
{
Encoding ascii = Encoding.ASCII;
//遍历图像文件元数据,检索所有属性
foreach (System.Drawing.Imaging.PropertyItem p in parr)
{
//如果是PropertyTagDateTime,则返回该属性所对应的值
if (p.Id == 0x0132)
{
return ascii.GetString(p.Value);
}
}
//若没有相关的EXIF信息则返回N/A
return "N/A";
}
{
FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
//通过指定的数据流来创建Image
System.Drawing.Image image = System.Drawing.Image.FromStream(stream, true, false);
PropertyItem[] r = image.PropertyItems;
stream.Close();
return r;
}
private string GetTakePicDateTime(System.Drawing.Imaging.PropertyItem[] parr)
{
Encoding ascii = Encoding.ASCII;
//遍历图像文件元数据,检索所有属性
foreach (System.Drawing.Imaging.PropertyItem p in parr)
{
//如果是PropertyTagDateTime,则返回该属性所对应的值
if (p.Id == 0x0132)
{
return ascii.GetString(p.Value);
}
}
//若没有相关的EXIF信息则返回N/A
return "N/A";
}