使用 System.Drawing.Image 时如何确定 jpeg 中标题的 ID

How do I determine the Id for the title in jpeg when using System.Drawing.Image

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

这是我的 ChangeFileProperties class:

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

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

An exception of type 'System.ArgumentException' occurred in System.Drawing.dll but was not handled in user code

Additional information: Property cannot be found.

好像id不对,怎么知道每个属性的id是什么。

如果你使用Image.PropertyItems集合,你可以获得所有属性并循环遍历它们:

var image = System.Drawing.Image.FromFile(@"C:\Users\wired\Pictures96422850103.jpeg");

foreach (var prop in image.PropertyItems)
{
    var id = prop.Id;
    //etc
}