On Thu, Mar 8, 2012 at 6:39 PM, Kasper Føns <kfo...@gmail.com> wrote:
>
>> I wouldn't count on Windows Explorer to give you the right values.
>> Rather check it against exiftool
>> (www.sno.phy.queensu.ca/~phil/exiftool/):
>> exiftool -a -g1 -u image.tiff
>>
>> Windows Explorer also likes the "XP" values (eg. EXIF_TAG_XPCOMMENT,
>> EXIF_TAG_XPAUTHOR), maybe try writing those as well?
>>
>> Damjan
>>
> Sorry for asking so many questions :( I hope it is okay.

Yes it's okay :).

> Hmm. It does not seem like the XP values work. They do not show correctly.
>
> Anyways, I tried using the code I sent you without special characters:
> byte[] bytesComment =
> ExifTagConstants.EXIF_TAG_USER_COMMENT.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_ASCII,
> "KasperComment", set.byteOrder);
> byte[] bytesAuthor =
> TiffTagConstants.TIFF_TAG_ARTIST.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_ASCII,
> "KasperAuthor", set.byteOrder);
>
> TiffOutputField commentField = new
> TiffOutputField(ExifTagConstants.EXIF_TAG_USER_COMMENT,
> ExifTagConstants.EXIF_TAG_USER_COMMENT.dataTypes[0], bytesComment.length,
> bytesComment);
> TiffOutputField authorField = new
> TiffOutputField(TiffTagConstants.TIFF_TAG_ARTIST,
> TiffTagConstants.TIFF_TAG_ARTIST.dataTypes[0], bytesAuthor.length,
> bytesAuthor);
> set.getOrCreateExifDirectory().add(commentField);
> set.getOrCreateRootDirectory().add(authorField);
>
> Then the exif tools shows (and so do windows explorer):
> ---- IFD0 ----
> Artist                          : KasperAuthor
> ---- ExifIFD ----
> User Comment                    : KasperComment
> ---- JFIF ----
> JFIF Version                    : 1.01
>
> However, trying the same, but adding an å to KasperComment and KasperAuthor
> gives the following:
> ---- IFD0 ----
> Artist                          : KasperAuthorå
> ---- ExifIFD ----
> User Comment                    : 䭡獰敲䍯浭敮瓃
> ---- JFIF ----
> JFIF Version                    : 1.01
>
> It seems the UserComment has been destroyed. Now it is suddenly chinese
> characters!?
> Windows explorer shows the artist but not the usercomment.
>
> Is this something to do with ExifDirectory vs RootDirectory?

No, the directory wouldn't affect the output.

Sanselan 0.97:
* doesn't null-terminate ASCII strings (eg. Artist), so you have to
allocate a byte array one element bigger and copy the encoded bytes to
it.
* uses the system locale for ASCII encoding, which is UTF-16LE on
Windows, even though TIFF requires UTF-8

So for ASCII fields instead of using encodeValue(), use
getBytes("UTF-8") and copy to a byte array with one more element (so
that the last element is null) like I showed you in the previous
email.

For UserComment what Sanselan does is autodetect the encoding: this
will work for ASCII and write ASCII, but in 0.97 it wrongly assumed
that the unicode encoding is UTF-8, whereas it's actually UTF-16 with
byte ordering depending on the file's byte ordering. So in 0.97 you
have to encode this manually yourself using a big hack:

byte[] unicodeMarker = new byte[]{ 0x55, 0x4E, 0x49, 0x43, 0x4F, 0x44,
0x45, 0x00 };
byte[] comment = "My Comment".getBytes("UTF-16LE"); // OR UTF-16BE if
the file is big-endian!
byte[] bytesComment = new byte[unicodeMarker.length + comment.length];
System.arraycopy(marker, 0, bytesComment, 0, marker.length);
System.arraycopy(comment, 0, bytesComment, marker.length, comment.length);
TiffOutputField commentField = new
  TiffOutputField(ExifTagConstants.EXIF_TAG_USER_COMMENT,
  ExifTagConstants.EXIF_TAG_USER_COMMENT.dataTypes[0], bytesComment.length,
  bytesComment);


We can safely conclude from this that there is many reasons why 1.0
needs to be released, and 0.97 needs to die :).

>
> /Kasper
>

Damjan

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

Reply via email to