到目前为止,我创建了一个简单的上传函数,下载函数和一个类来更改文件属性,但是现在如何确定我想要更改的属性或属性的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 }更多推荐
发布评论