Results 1 to 3 of 3
  1. #1
    nancyhung is offline Member
    Join Date
    Jan 2008
    Posts
    5
    Rep Power
    0

    Unhappy get Photo taken date

    hi,

    I have some photos taken.
    I would like to ask how to get the photo taken date from the JPEG file?

    I have found the information of EXIF and MetaData, but i don't know how to implement with the code in order to get the Date....

    Can anyone help me ??

  2. #2
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    9

    Default

    Last edited by DonCash; 04-07-2008 at 01:35 PM.
    Did this post help you? Please me! :cool:

  3. #3
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    9

    Default

    The Java program given below reads the metadata from one or more image files given as arguments to the program. The metadata is read into an XML Document Object Model (DOM) tree, and a simple method is used to print each element and attributes (if present).
    Java Code:
    import org.w3c.dom.*;
    
    import java.io.*;
    import java.util.*;
    import javax.imageio.*;
    import javax.imageio.stream.*;
    import javax.imageio.metadata.*;
    
    public class Metadata {
    
        public static void main(String[] args) {
            Metadata meta = new Metadata();
            int length = args.length;
            for ( int i = 0; i < length; i++ )
                meta.readAndDisplayMetadata( args[i] );
        }
    
        void readAndDisplayMetadata( String fileName ) {
            try {
    
                File file = new File( fileName );
                ImageInputStream iis = ImageIO.createImageInputStream(file);
                Iterator<ImageReader> readers = ImageIO.getImageReaders(iis);
    
                if (readers.hasNext()) {
    
                    // pick the first available ImageReader
                    ImageReader reader = readers.next();
    
                    // attach source to the reader
                    reader.setInput(iis, true);
    
                    // read metadata of first image
                    IIOMetadata metadata = reader.getImageMetadata(0);
    
                    String[] names = metadata.getMetadataFormatNames();
                    int length = names.length;
                    for (int i = 0; i < length; i++) {
                        System.out.println( "Format name: " + names[ i ] );
                        displayMetadata(metadata.getAsTree(names[i]));
                    }
                }
            }
            catch (Exception e) {
    
                e.printStackTrace();
            }
        }
    
        void displayMetadata(Node root) {
            displayMetadata(root, 0);
        }
    
        void indent(int level) {
            for (int i = 0; i < level; i++)
                System.out.print("    ");
        }
    
        void displayMetadata(Node node, int level) {
            // print open tag of element
            indent(level);
            System.out.print("<" + node.getNodeName());
            NamedNodeMap map = node.getAttributes();
            if (map != null) {
    
                // print attribute values
                int length = map.getLength();
                for (int i = 0; i < length; i++) {
                    Node attr = map.item(i);
                    System.out.print(" " + attr.getNodeName() +
                                     "=\"" + attr.getNodeValue() + "\"");
                }
            }
    
            Node child = node.getFirstChild();
            if (child == null) {
                // no children, so close element and return
                System.out.println("/>");
                return;
            }
    
            // children, so close current tag
            System.out.println(">");
            while (child != null) {
                // print children recursively
                displayMetadata(child, level + 1);
                child = child.getNextSibling();
            }
    
            // print close tag of element
            indent(level);
            System.out.println("</" + node.getNodeName() + ">");
        }
    }
    Example output:

    Java Code:
    java Metadata frog-2.png
    Format name: javax_imageio_png_1.0
    <javax_imageio_png_1.0>
        <IHDR width="96" height="96" bitDepth="8" colorType="RGB"
    compressionMethod="deflate" filterMethod="adaptive" interlaceMethod="none"/>
    </javax_imageio_png_1.0>
    Format name: javax_imageio_1.0
    <javax_imageio_1.0>
        <Chroma>
            <ColorSpaceType name="RGB"/>
            <NumChannels value="3"/>
            <BlackIsZero value="true"/>
        </Chroma>
        <Compression>
            <CompressionTypeName value="deflate"/>
            <Lossless value="true"/>
            <NumProgressiveScans value="1"/>
        </Compression>
        <Data>
            <PlanarConfiguration value="PixelInterleaved"/>
            <SampleFormat value="UnsignedIntegral"/>
            <BitsPerSample value="8 8 8"/>
        </Data>
        <Dimension>
            <PixelAspectRatio value="1.0"/>
            <ImageOrientation value="Normal"/>
        </Dimension>
        <Transparency>
            <Alpha value="none"/>
        </Transparency>
    </javax_imageio_1.0>
    All the above can be found here:

    Obtaining image metadata using the Java Image I/O API
    Last edited by DonCash; 04-07-2008 at 06:13 PM.
    Did this post help you? Please me! :cool:

Similar Threads

  1. java.util.Date vs java.sql.Date
    By Jack in forum New To Java
    Replies: 5
    Last Post: 10-28-2010, 03:59 PM
  2. Difference between current date and anothe date
    By vijay balusamy in forum New To Java
    Replies: 1
    Last Post: 04-16-2008, 05:15 PM
  3. Connect Java application to photo editor
    By syellows in forum Advanced Java
    Replies: 1
    Last Post: 11-21-2007, 01:09 AM
  4. Date Inputs
    By hiranya in forum AWT / Swing
    Replies: 3
    Last Post: 11-06-2007, 06:11 PM
  5. Date math
    By orchid in forum New To Java
    Replies: 2
    Last Post: 04-18-2007, 08:01 AM

Posting Permissions

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