使用System.Drawing.Image时,如何确定jpeg格式标题的Id



到目前为止,我创建了一个简单的上传函数,下载函数和a类来更改文件属性,但是现在如何确定要更改的属性或属性的Id。标题、作者、主题等 目前我正在为我的图书馆使用System.Drawing.Imaging.dll。

这是我在ChangeFileProperties课上取得的成绩:

public class ChangeFileProperties
{ 
public void ChangeFileAuthor(string FilePath)
{
System.Drawing.Image image = System.Drawing.Image.FromFile(FilePath);
//??
PropertyItem propitem = image.GetPropertyItem(0x0320);
//??
propitem.Id = 0x0321;
propitem.Len = propitem.Value.Length;
propitem.Type = 1;
propitem.Value = Encoding.UTF8.GetBytes("MyImageInfo");
image.SetPropertyItem(propitem);

image.Save(Environment.CurrentDirectory + @"test.jpeg");
}
}

所以现在,代码中没有错误,但是当我运行网页时,错误会在??评论部分弹出,错误说

System.Drawing中发生了类型为"System.ArgumentException"的异常.dll但未在用户代码中处理

其他信息:找不到属性。

似乎 Id 是错误的,那么我怎么知道每个属性的 Id 是什么。

如果使用Image.PropertyItems集合,则可以获取所有属性并遍历它们:

var image = System.Drawing.Image.FromFile(@"C:UserswiredPictures1496422850103.jpeg");
foreach (var prop in image.PropertyItems)
{
var id = prop.Id;
//etc
}

相关内容

最新更新