Here is the program I was using and the file that has metadata.

1test.jpg has only the JPEG Comment (view by using exiftool for
example), when I run the attached ExifTest.java program I get a null
metadata object.

vegas.jpg is from a camera, I get metadata but can not find the comment
(JPEG COM) anywhere in it

Regards
Erlend

> 
> I'm checking. If not, I'll make you a patch. Can you email me an image to
> test with?
> 
> Regards
> Damjan

import java.io.File;

import javax.swing.JOptionPane;

import org.apache.sanselan.Sanselan;
import org.apache.sanselan.common.IImageMetadata;
import org.apache.sanselan.formats.jpeg.JpegImageMetadata;
import org.apache.sanselan.formats.tiff.TiffField;
import org.apache.sanselan.formats.tiff.TiffImageMetadata;

public class ExifTest {

    public static void main(String[] args) {
        String filename = "";
        if (args.length != 1) {
            filename = JOptionPane.showInputDialog("Enter filename");
        } else {
            filename = args[0];
        }
        File file = new File(filename);
        if (!file.exists() || !file.canRead()) {
            System.out.println("File not found or not readable: " + file.getAbsolutePath());
            System.exit(0);
        }

        try {
          
            IImageMetadata meta = Sanselan.getMetadata(file);
            System.out.println("got metadata = " + meta);
            
//            ImageInfo info = Sanselan.getImageInfo(file);
//            System.out.println(" info, # of comments = " + info.getComments().size() );            
//            info.dump();
            printMetaData(meta);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    
    public static void printMetaData(IImageMetadata meta) throws Exception {
        if (meta instanceof JpegImageMetadata) {
            // write all items
            System.out.println("ITEMS: " + meta.getItems().size());
            System.out.println("==============");
            for (Object o : meta.getItems()) {
                System.out.println("   item: " + o);
            }

            // write all exif data
            TiffImageMetadata exif = ((JpegImageMetadata) meta).getExif();
            System.out.println("\n\n\n\n\n\n\nEXIF: " + exif.getAllFields().size());
            for (Object o : exif.getAllFields()) {
                TiffField f = (TiffField) o;
                System.out.println("   " + f.getDescriptionWithoutValue() + " = " + f.getValue());
            }
        } else if(meta == null) {
            System.out.println("META is null");
        }
        else {
            System.out.println("Unsupported image type (not jpeg): " + meta.getClass());
        }
    }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to