【发布时间】:2020-02-15 09:43:36
【问题描述】:
我想用 C# 设置 DateTaken 参数,因为我有很多没有这个日期的照片。 我只找到了这条评论changing-datetaken-of-a-photo 在这个主题中,他们正在更改它而不是创建它。
如果使用该函数,但DataTakenProperty1或DataTakenProperty2为null,不能设置。
private static void SetDateTaken(string path, DateTime NEWdate)
{
Image theImage = new Bitmap(path);
PropertyItem[] propItems = theImage.PropertyItems;
Encoding _Encoding = Encoding.UTF8;
var DataTakenPropert = propItems.SetValue(NEWdate.ToString("yyyy:MM:dd HH:mm:ss"), ??How do i know the index??);
theImage.SetPropertyItem(DataTakenProperty);
string new_path = Path.GetDirectoryName(path) + "\\_" + Path.GetFileName(path);
theImage.Save(new_path);
theImage.Dispose();
}
感谢您的帮助
【问题讨论】: