/// <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 "";
        }

 

相关文章:

  • 2021-08-23
  • 2021-10-24
  • 2022-12-23
  • 2021-06-18
  • 2022-12-23
  • 2021-10-01
  • 2021-10-31
猜你喜欢
  • 2021-06-20
  • 2022-12-23
  • 2022-01-14
  • 2021-08-21
  • 2022-12-23
  • 2021-10-26
  • 2021-12-01
相关资源
相似解决方案