【发布时间】:2014-01-03 06:44:31
【问题描述】:
我在修改元数据后保存图像时遇到问题。 基本上,我想打开我的图像,显示它,修改它的 EXIF 元数据,然后保存它。
首先,我在尝试保存图像时遇到了问题,因为原始文件已被锁定(我遇到了一般性 GTI+ 错误)。在阅读了这里的一些帖子并发现问题后,我使用 using 关键字解决了锁定问题。
但问题是,如果我使用“using”,我的 Image 的 propertyItems 列表是空的,我无法修改我的元数据。
这是我加载图像的方式(使用不同的测试)
this.image = new Bitmap(this.path); // this cause lock on file
/* the following doesn't lock the file, but image.propertyItems is empty */
//using (var bmpTemp = new Bitmap(this.path))
//{
// this.image = new Bitmap(bmpTemp);
//}
使用 streamReader 或 MemoryStream 没有帮助...
这是我修改和保存图像的方法:
PropertyItem p = this.photo.Image.GetPropertyItem(0x5090);
p.Id = 0x320;
p.Type = 2; // Type ASCII
p.Len = boxTitle.Text.Length;
p.Value = Encoding.ASCII.GetBytes(boxTitle.Text);
this.photo.Image.SetPropertyItem(p);
this.photo.Image.Save(this.photo.Path);
你能解释一下为什么我使用“使用”时没有propertyItems,我该如何修改图像元数据而不是保存它?
【问题讨论】:
-
它似乎有效,但是为每张图片读取/写入元数据会导致大量图片出现性能问题