/// <summary>
/// 获取Exif中的照片拍摄日期
/// </summary>
/// <param name="fileName">文件名</param>
/// <returns>拍摄日期</returns>
private string GetTakePicDate(string fileName)
{
Encoding ascii = Encoding.ASCII;
string picDate; FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
Image image = Image.FromStream(stream, true, false); foreach (PropertyItem p in image.PropertyItems)
{
//获取拍摄日期时间
if (p.Id == 0x9003) // 0x0132 最后更新时间
{
stream.Close(); picDate = ascii.GetString(p.Value);
if ((!"".Equals(picDate)) && picDate.Length >= 10)
{
// 拍摄日期
picDate = picDate.Substring(0, 10);
picDate = picDate.Replace(":","-");
return picDate;
}
}
}
stream.Close();
return "";
}