在使用System.Drawing.Image时,如何确定jpeg中标题的ID(How do I determine the Id for the title in jpeg when using S

编程入门 行业动态 更新时间:2024-10-25 00:26:32
在使用System.Drawing.Image时,如何确定jpeg中标题的ID(How do I determine the Id for the title in jpeg when using System.Drawing.Image)

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

这与我的ChangeFileProperties类有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.dll中发生类型'System.ArgumentException'的异常,但未在用户代码中处理

附加信息:无法找到物业。

这似乎是错的,所以我怎么知道每个属性的Id是什么。

So far I created a simple upload function, download function and the a class to change file properties, but right now how do I determine the Id for the attributes or properties I want to change eg. Title, Author, Subject, etc. Currently I'm using System.Drawing.Imaging.dll for my library.

This is how far I got with my 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"); } }

So right now, there no error in the codes but when I run the webpage, the errors pop up on the ?? comment part, the errors said

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

Additional information: Property cannot be found.

It seems the Id is wrong, so how do I know what Id is it for each attributes.

最满意答案

如果您使用Image.PropertyItems集合,则可以获取所有属性并循环访问它们:

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

If you use the Image.PropertyItems collection, you can get all the properties and loop through them:

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

更多推荐

本文发布于:2023-08-07 21:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466406.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标题   Image   jpeg   System   Drawing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!