Hi Arnaud,

   Sorry, the sample code could have been more clear on that point.

   I've changed the changeExifMetadata() method of
WriteExifMetadataExample like so:

>>>
// new import
import org.apache.sanselan.common.BinaryConstants;
...

        public void changeExifMetadata(File jpegImageFile, File dst)
                        throws IOException, ImageReadException, 
ImageWriteException
        {
                OutputStream os = null;
                try
                {
                        TiffOutputSet outputSet =  null;

                        // note that metadata might be null if no metadata is 
found.
                        IImageMetadata metadata = 
Sanselan.getMetadata(jpegImageFile);
                        JpegImageMetadata jpegMetadata = (JpegImageMetadata) 
metadata;
                        if (null != jpegMetadata)
                        {
                                // note that exif might be null if no Exif 
metadata is found.
                                TiffImageMetadata exif = jpegMetadata.getExif();

                                if (null != exif)
                                {
                                        // TiffImageMetadata class is immutable 
(read-only).
                                        // TiffOutputSet class represents the 
Exif data to write.
                                        //
                                        // Usually, we want to update existing 
Exif metadata by changing
                                        // the values of a few fields, or 
adding a field.
                                        // In these cases, it is easiest to use 
getOutputSet() to
                                        // start with a "copy" of the fields 
read from the image.
                                         outputSet = exif.getOutputSet();
                                }
                        }
                        
                        if(null==outputSet)
                                outputSet =  new 
TiffOutputSet(BinaryConstants.BYTE_ORDER_INTEL);

...
>>>

   Simply put, if the image file doesn't contain any Exif metadata,
create a new instance of the TiffOutputSet data structure and use it
instead of one derived from old metadata.

   I hope you find this helpful.

Charles.


I've cc'd the sanselan-dev mailing list again.

On Feb 2, 2008 9:23 AM, Arnaud Mondit <[EMAIL PROTECTED]> wrote:
> Hi, it's me again :)
>
> Your advices helped me a lot writing GPS metadata into jpeg files, but now
> I'm facing new problems.
>
> The software I'm writing takes picture files from a folder and then places
> them on a "google maps"-like map (using gps coordinates and the swingx-ws
> library), and also provides the ability to set gps coordinates to untagged
> pictures. That works quite well using your library with pictures that
> already have metadata, but not at all with picture that dont (those which
> Sanselan.getMetadata(picture) returns null).
>
> Is there any way to generate metadata (without informations) so that I could
> write GPS metadata in it and then write it back to the file ? I couldn't
> find any indications for that in your examples or in your code.
>
> Thanks again.
>
> Arnaud Mondit
>

Reply via email to