0

Hope to seek some help. I am trying to add some text to Exif field ImageDescription(270). I am partially successful. Here is the code

pitem.Id = 270;
  pitem.Type = 2;
      byte[] utf16Bytes = Encoding.Unicode.GetBytes("Testing ImageDescription from command line.");
      byte[] utf8Bytes = Encoding.Convert(Encoding.Unicode, Encoding.UTF8, utf16Bytes);
  pitem.Value = utf8Bytes;//utf16Bytes 
  image.SetPropertyItem(pitem);

I then save image copy at new path, then I try to read back the property just added. THIS is where I am so failing..:-( For some reason this field is not taking more then 6 characters, I have tried many things including change data to UTF-8 byte array, adding null-terminator (\0), even tried another field (305) with the same issue there as well, field will not take more then 6 characters.. I am not being able to see the full text being added to the field. Can some one guide..

Thanks

4

1 回答 1

0

2件事:

(a) 查看PropertyItem.Type定义:

1:指定 Value 是一个字节数组。

2:指定 Value 是以 null 结尾的 ASCII 字符串。如果将类型数据成员设置为 ASCII 类型,则应将 Len 属性设置为字符串的长度,包括空终止符。例如,字符串“Hello”的长度为 6。

看起来您使用错误-应该是(1)-然后您应该保存字节数组,或者应该是(2)-但是您需要将ASCII字符串传递给它。

也看看这个问题:Set image meta data before save

(b) 将 ptype.Len 属性设置为字符串的长度。

http://msdn.microsoft.com/en-us/library/system.drawing.imaging.propertyitem.type.aspx

于 2013-09-03T05:23:27.393 回答