commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joakim Knudsen <>
Subject Creating EXIF tags (TiffOutputField) the right way
Date Sat, 21 May 2016 17:29:36 GMT
Hi List!

I'm working on an Android app, where I want to read and write "EXIF tags"
to JPEG files on the device. Sanselan 0.97 seems to work perfectly,
although it's a bit complicated to work with EXIF tags/directories.

The specific tags I'm interested in, is EXIF_TAG_USER_COMMENT and
According to the documentation I could find, UserComment is of field type
"undefined", whereas ImageDescription is of field type ASCII.

What's the proper way of creating those tags, wrt. charset etc? I want as
wide as possible character support (æøå etc).

I find different discussions online, with different advice. Seems two
constructors are going around, where the simpler one does not deal with
charset/encoding at all. This one uses the .create method:

String textToSet = "Some Text æøå";

TiffOutputField exif_comment = TiffOutputField.create(
                outputSet.byteOrder, textToSet);

while this one uses the standard constructor:

byte b[] = ExifTagConstants.EXIF_TAG_USER_COMMENT.encodeValue(
        textToSet, outputSet.byteOrder

// constructor arguments: taginfo tag fieldtype count bytes
TiffOutputField exif_comment2 = new
        b.length, b);

In this last one, the string to set has been converted to a byte array
first. But can/should I set the encoding anywhere?

Is the field type even ASCII? This information seems to indicate it's
not ASCII...

Need some help here, as you can see, to get this right. The second
approach above does seem to work in my app, but I'd like to be sure
I'm not somehow messing up the JPEGs on the deviced.


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message