Hello list,
I'm new to Sanselan and i am currently trying to set values for fields in a jpg
with sanselan-0.97-incubator.jar. I want this, because our webserver provides
us jpeg images and we want to add some meta data, which can be used by the
client. Typically this are the gpslocation (already working), recording data /
direction and other parameters.
This works fine for the fields EXIF_TAG_DATE_TIME_ORIGINAL /
EXIF_TAG_CREATE_DATE using the following code:
> taginfo = TiffConstants.EXIF_TAG_DATE_TIME_ORIGINAL;
> if (outputSet.findField(taginfo) != null) outputSet.removeField(taginfo);
> exifdata = new TiffOutputField(taginfo,
> TiffFieldTypeConstants.FIELD_TYPE_BYTE, tagbytes.length, tagbytes);
However, when i try to set the subject(string) with the following code (cleaned
/ removed comments, so i hope there are no typo's. Also i tried:
EXIF_TAG_XPCOMMENT / EXIF_TAG_XPAUTHOR which returned the same error)
> byte[] SetSubjectTest(byte[] data) {
> tagbytes = formatter.format(image.getFrame().getTraveldate()).getBytes();
> TiffOutputSet outputSet = null;
> IImageMetadata metadata = Sanselan.getMetadata(data);
> JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
> if (null != jpegMetadata)
> {
> TiffImageMetadata exif = jpegMetadata.getExif();
> if (null != exif)
> {
> outputSet = exif.getOutputSet();
> }
> }
> if (null == outputSet) {
> outputSet = new TiffOutputSet();
> }
> TagInfo taginfo = TiffConstants.EXIF_TAG_XPSUBJECT;
> if (outputSet.findField(taginfo) != null)
> outputSet.removeField(taginfo);
> String tagstring = "test";
> /*
> // next lines give strange results in ExifToolGui, something like:
> "ÒæÑµÉ¦Òö¦µöÁÒëªÔ¦©Òÿ¦ÒìñÒñ¡µö¦Ô¦©ÒòúÒòñÒàªÒتµä¦Òòñ"
> byte[] tagbytes = tagstring.getBytes();
> exifdata = new TiffOutputField(taginfo,
> TiffFieldTypeConstants.FIELD_TYPE_BYTE, tagbytes.length, tagbytes);
> */
> TiffOutputField exifdata = TiffOutputField.create(taginfo,
> outputSet.byteOrder, tagstring);
>
> ^^^^^^
> TiffOutputDirectory exifDirectory =
> outputSet.getOrCreateExifDirectory();
> exifDirectory.add(exifdata);
> ByteArrayOutputStream os = new ByteArrayOutputStream(data.length);
> ExifRewriter writer = new ExifRewriter();
> writer.updateExifMetadataLossless(data, os, outputSet);
> data = os.toByteArray();
> os.close();
> os = null;
> return data;
> }
I get the following error:
> org.apache.sanselan.ImageWriteException: Tag has unexpected data type.
>
> org.apache.sanselan.formats.tiff.write.TiffOutputField.create(TiffOutputField.java:105)
How can i set string-data in the exif-header?
Also, since we want to store key/value pairs, which field is best to use for
this (mis)usage?
Cheers,
Eduard Witteveen
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]