Set image meta data before save

不想你离开。 提交于 2019-12-01 01:12:27

Well, after some tests, this works... But only if property 40091 doesn't exist in the original Image. If it exists, it's not replaced (must admit I don't know why).

 var image = Image.FromFile(@"C:\Tools\test.jpg");
 var propertyItem = createPropertyItem();
 var text = "awe" + char.MinValue;//add \0 at the end of your string
 propertyItem = createPropertyItem();
 propertyItem.Id = 40091;
 propertyItem.Value = Encoding.Unicode.GetBytes(text);//change to Unicode
 propertyItem.Len = propertyItem.Value.Length;
 propertyItem.Type = 1;//it's not type 2 !
 image.SetPropertyItem(propertyItem);
 image.Save(@"C:\Tools\test2.jpg");
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!