Set image meta data before save

前端 未结 1 971
逝去的感伤
逝去的感伤 2021-01-07 09:49

I\'m trying to set the metadata of an image on exit from a resize, the property appears to be set but after the save nothing is there.

I\'m pretty sure I\'m doing so

1条回答
  •  春和景丽
    2021-01-07 10:17

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

    0 讨论(0)
提交回复
热议问题