commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Damjan Jovanovic <dam...@apache.org>
Subject Re: [sanselan] Writing EXIF data to JPEG
Date Thu, 08 Mar 2012 17:14:04 GMT
On Thu, Mar 8, 2012 at 7:02 PM, Kasper Føns <kfoens@gmail.com> wrote:
>
>> Windows Explorer also likes the "XP" values (eg. EXIF_TAG_XPCOMMENT,
>> EXIF_TAG_XPAUTHOR), maybe try writing those as well?
>
> Hmm. You seem to be right that explorer likes the XP values. However, I
> can't figure out how to write to them. I can see that they are BYTE values,
> but how to convert a string into the wanted bytes?
>
> This is the result I get:
> ---- IFD0 ----
> XP Comment                      : 態灳牥潃浭湥t
> XP Author                       : 態灳牥畁桴牯
>
> With this code:
> byte[] bytesComment =
> ExifTagConstants.EXIF_TAG_XPCOMMENT.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_ASCII,
> "KasperComment", set.byteOrder);
> byte[] bytesAuthor =
> ExifTagConstants.EXIF_TAG_XPAUTHOR.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_ASCII,
> "KasperAuthor", set.byteOrder);
> TiffOutputField commentField = new
> TiffOutputField(ExifTagConstants.EXIF_TAG_XPCOMMENT,
> ExifTagConstants.EXIF_TAG_XPCOMMENT.dataTypes[0], bytesComment.length,
> bytesComment);
> TiffOutputField authorField = new
> TiffOutputField(ExifTagConstants.EXIF_TAG_XPAUTHOR,
> ExifTagConstants.EXIF_TAG_XPAUTHOR.dataTypes[0], bytesAuthor.length,
> bytesAuthor);
> set.getOrCreateRootDirectory().add(commentField);
> set.getOrCreateRootDirectory().add(authorField);
>
>
> /Kasper

There's no easy way in Sanselan 0.97: the XP fields use little-endian
UTF-16 (no matter what the byte ordering of the file is, thanks
Microsoft you useless @*#%!) so try this:

byte[] rawBytes = "KasperAuthor".getBytes("UTF-16LE");
byte[] nullTerminatedBytes = new byte[rawBytes.length + 2];
TiffOutputField authorField = new
  TiffOutputField(ExifTagConstants.EXIF_TAG_XPAUTHOR,
  ExifTagConstants.EXIF_TAG_XPAUTHOR.dataTypes[0], nullTerminatedBytes.length,
  nullTerminatedBytes);

Damjan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message