【发布时间】:2018-07-05 10:20:55
【问题描述】:
我已经创建了一些函数来编辑 Jpeg 图像的 Exif 元数据,现在我可以编辑评论但是当我尝试编辑我的标题时它不起作用,没有显示错误,我想要通过替换原始文件来保存它,这是我到目前为止创建的代码:
System.Drawing.Image image = null;
protected void EditCommentBtn_Click(object sender, EventArgs e)
{
image = System.Drawing.Image.FromFile(filepath);
PropertyItem propItem = image.PropertyItems[0];
using (var file = System.Drawing.Image.FromFile(filepath))
{
propItem.Id = 0x9286; //Usercomment
propItem.Type = 2;
propItem.Value = System.Text.Encoding.UTF8.GetBytes("HelloWorld\0");
propItem.Len = propItem.Value.Length;
file.SetPropertyItem(propItem);
PropertyItem propItem1 = file.PropertyItems[file.PropertyItems.Count() - 1];
string newFilename = "newfilename.jpg";
file.Save(newFilename, ImageFormat.Jpeg);
}
}
protected void EditTitleBtn_Click(object sender,EventArgs e)
{
image = System.Drawing.Image.FromFile(filepath);
PropertyItem propItem = image.PropertyItems[0];
using (var file = System.Drawing.Image.FromFile(filepath))
{
propItem.Id = 0x0320; //Title
propItem.Type = 2;
propItem.Value = System.Text.Encoding.UTF8.GetBytes("testtitle\0");
propItem.Len = propItem.Value.Length;
file.SetPropertyItem(propItem);
PropertyItem propitem1 = file.PropertyItems[file.PropertyItems.Count() - 1];
string newFilename = "newfilename.jpg";
if (File.Exists(filepath))
{
image.Dispose();
File.Delete(filepath);
}
file.Save(newFilename, ImageFormat.Jpeg);
}
}
保存文件时出现错误显示,因为我想替换已编辑的 jpeg,我尝试使用 File.Exits 和 File.Delete 但它对我不起作用,这是错误显示
进程无法访问文件“文件路径”,因为它正在 被另一个进程使用
虽然我事先处理了图像,但我可以删除其他文件,只是不能删除我在if 块中检查条件的文件。
所以现在我现在遇到的问题是
1.不能更改 Jpeg 图像标题的 Exif 元数据(已解决)
2.不能替换原始 jpeg带有编辑后的 jpeg 文件的文件
【问题讨论】:
标签: c# asp.net metadata jpeg exif