Results 1 to 4 of 4
  1. #1
    norazanita is offline Member
    Join Date
    Jun 2008
    Posts
    6
    Rep Power
    0

    Default how to extract the date n time from images

    can anybody help me...what function/ method that i can use to extract the date an time from images

    thanks
    :(

  2. #2
    Niveditha's Avatar
    Niveditha is offline Senior Member
    Join Date
    May 2008
    Posts
    307
    Rep Power
    7

    Default

    Hi,
    Can u provide more details like how your image looks like?
    I meant to say does it have date n time printed on it.

  3. #3
    norazanita is offline Member
    Join Date
    Jun 2008
    Posts
    6
    Rep Power
    0

    Default

    what i want exactly is to extract the metadata from the images/photos (from digicam and such), more specifically the time and date of capture. just want to know if there is such function in java.

  4. #4
    Niveditha's Avatar
    Niveditha is offline Senior Member
    Join Date
    May 2008
    Posts
    307
    Rep Power
    7

    Thumbs up To extract created date and time

    Hi,
    The following code extracts image into a metadata and get the date and time of a image,
    It requires something called sanselan for support of images in java

    I was not able to post its link as my posts num is not 20.
    Do a google on sanselan.zip and you may find it.


    Hope it works...


    package org.cmc.sanselan.sampleUsage;

    import java.io.File;
    import java.io.IOException;
    import java.util.ArrayList;

    import org.cmc.sanselan.ImageReadException;
    import org.cmc.sanselan.Sanselan;
    import org.cmc.sanselan.common.IImageMetadata;
    import org.cmc.sanselan.common.RationalNumber;
    import org.cmc.sanselan.formats.jpeg.JpegImageMetadata;
    import org.cmc.sanselan.formats.tiff.TiffField;
    import org.cmc.sanselan.formats.tiff.TiffImageMetadata;
    import org.cmc.sanselan.formats.tiff.constants.TagInfo;
    import org.cmc.sanselan.formats.tiff.constants.TiffConsta nts;

    public class MetadataExample
    {
    public static void metadataExample(File file) throws ImageReadException,
    IOException
    {
    // get all metadata stored in EXIF format (ie. from JPEG or TIFF).
    // org.w3c.dom.Node node = Sanselan.getMetadataObsolete(imageBytes);
    IImageMetadata metadata = Sanselan.getMetadata(file);

    //System.out.println(metadata);

    if (metadata instanceof JpegImageMetadata)
    {
    JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;

    // Jpeg EXIF metadata is stored in a TIFF-based directory structure
    // and is identified with TIFF tags.
    // Here we look for the "x resolution" tag, but
    // we could just as easily search for any other tag.
    //
    // see the TiffConstants file for a list of TIFF tags.

    System.out.println("file: " + file.getPath());

    // print out various interesting EXIF tags.
    printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_XRESOLUTION);
    printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_DATE_TIME);
    printTagValue(jpegMetadata,
    TiffConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
    printTagValue(jpegMetadata, TiffConstants.EXIF_TAG_CREATE_DATE);
    printTagValue(jpegMetadata, TiffConstants.EXIF_TAG_ISO);
    printTagValue(jpegMetadata,
    TiffConstants.EXIF_TAG_SHUTTER_SPEED_VALUE);
    printTagValue(jpegMetadata, TiffConstants.EXIF_TAG_APERTURE_VALUE);
    printTagValue(jpegMetadata, TiffConstants.EXIF_TAG_BRIGHTNESS_VALUE);
    printTagValue(jpegMetadata, TiffConstants.GPS_TAG_GPS_LATITUDE_REF);
    printTagValue(jpegMetadata, TiffConstants.GPS_TAG_GPS_LATITUDE);
    printTagValue(jpegMetadata, TiffConstants.GPS_TAG_GPS_LONGITUDE_REF);
    printTagValue(jpegMetadata, TiffConstants.GPS_TAG_GPS_LONGITUDE);

    System.out.println();

    // simple interface to GPS data
    TiffImageMetadata exifMetadata = jpegMetadata.getExif();
    if (null != exifMetadata)
    {
    TiffImageMetadata.GPSInfo gpsInfo = exifMetadata.getGPS();
    if (null != gpsInfo)
    {
    String gpsDescription = gpsInfo.toString();
    double longitude = gpsInfo.getLongitudeAsDegreesEast();
    double latitude = gpsInfo.getLatitudeAsDegreesNorth();

    System.out.println(" " + "GPS Description: " + gpsInfo);
    System.out.println(" " + "GPS Longitude (Degrees East): " + longitude);
    System.out.println(" " + "GPS Latitude (Degrees North): " + latitude);
    }
    }

    // more specific example of how to manually access GPS values
    TiffField gpsLatitudeRefField = jpegMetadata
    .findEXIFValue(TiffConstants.GPS_TAG_GPS_LATITUDE_ REF);
    TiffField gpsLatitudeField = jpegMetadata
    .findEXIFValue(TiffConstants.GPS_TAG_GPS_LATITUDE) ;
    TiffField gpsLongitudeRefField = jpegMetadata
    .findEXIFValue(TiffConstants.GPS_TAG_GPS_LONGITUDE _REF);
    TiffField gpsLongitudeField = jpegMetadata
    .findEXIFValue(TiffConstants.GPS_TAG_GPS_LONGITUDE );
    if (gpsLatitudeRefField != null && gpsLatitudeField != null
    && gpsLongitudeRefField != null
    && gpsLongitudeField != null)
    {
    // all of these values are strings.
    String gpsLatitudeRef = (String) gpsLatitudeRefField.getValue();
    RationalNumber gpsLatitude[] = (RationalNumber[]) (gpsLatitudeField
    .getValue());
    String gpsLongitudeRef = (String) gpsLongitudeRefField
    .getValue();
    RationalNumber gpsLongitude[] = (RationalNumber[]) gpsLongitudeField
    .getValue();

    RationalNumber gpsLatitudeDegrees = gpsLatitude[0];
    RationalNumber gpsLatitudeMinutes = gpsLatitude[1];
    RationalNumber gpsLatitudeSeconds = gpsLatitude[2];

    RationalNumber gpsLongitudeDegrees = gpsLongitude[0];
    RationalNumber gpsLongitudeMinutes = gpsLongitude[1];
    RationalNumber gpsLongitudeSeconds = gpsLongitude[2];

    // This will format the gps info like so:
    //
    // gpsLatitude: 8 degrees, 40 minutes, 42.2 seconds S
    // gpsLongitude: 115 degrees, 26 minutes, 21.8 seconds E

    System.out.println(" " + "GPS Latitude: "
    + gpsLatitudeDegrees.toDisplayString() + " degrees, "
    + gpsLatitudeMinutes.toDisplayString() + " minutes, "
    + gpsLatitudeSeconds.toDisplayString() + " seconds "
    + gpsLatitudeRef);
    System.out.println(" " + "GPS Longitude: "
    + gpsLongitudeDegrees.toDisplayString() + " degrees, "
    + gpsLongitudeMinutes.toDisplayString() + " minutes, "
    + gpsLongitudeSeconds.toDisplayString() + " seconds "
    + gpsLongitudeRef);

    }

    System.out.println();

    ArrayList items = jpegMetadata.getItems();
    for (int i = 0; i < items.size(); i++)
    {
    Object item = items.get(i);
    System.out.println(" " + "item: " + item);
    }

    System.out.println();
    }
    }

    private static void printTagValue(JpegImageMetadata jpegMetadata,
    TagInfo tagInfo) throws ImageReadException, IOException
    {
    TiffField field = jpegMetadata.findEXIFValue(tagInfo);
    if (field == null)
    System.out.println(tagInfo.name + ": " + "Not Found.");
    else
    System.out.println(tagInfo.name + ": "
    + field.getValueDescription());
    }

    }
    To finish sooner, take your own time....
    Nivedithaaaa

Similar Threads

  1. Formatting time and date
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 07:35 PM
  2. Date/Time Servlet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-14-2008, 09:34 AM
  3. File creating date/time
    By bugger in forum New To Java
    Replies: 1
    Last Post: 11-11-2007, 07:43 PM
  4. Time and Date in Java
    By java_fun2007 in forum New To Java
    Replies: 4
    Last Post: 11-06-2007, 07:25 PM
  5. how to get the current date and time
    By valery in forum New To Java
    Replies: 1
    Last Post: 08-03-2007, 06:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •