Solved

Read Date Photo Taken Programatically vb.net

Posted on 2011-02-23
3
878 Views
Last Modified: 2012-08-13
I am trying to figure out how to read the metadata information from a group of Jpeg images.  I want the Date and Time the Photo was taken and the MD5 of the photo so that I can deduplicate the photos.  I have a listing of the text Files with a CR LF in Textbox1  Any help in reading the header data or information of where I can find sample code is appreciated.
0
Comment
Question by:rphilipson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Author Comment

by:rphilipson
ID: 34964646
Meant to say I have a listing of the JPEG Files with CR LF on each line.
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 34965086
This "ExifTool" looks like it will extract the jpeg metadata, and it can be used from command line.  You can call it inside a DOS "FOR /F" loop to process your "file-of-files".  This should give you a start.

http://download.cnet.com/ExifTool/3000-6675_4-10791213.html
0
 
LVL 22

Accepted Solution

by:
pivar earned 500 total points
ID: 34965152
Hi,

Check these links:

http://msdn.microsoft.com/en-us/library/xddt0dz7.aspx
http://msdn.microsoft.com/en-us/library/system.drawing.imaging.propertyitem.id.aspx
http://stackoverflow.com/questions/221345/how-to-get-the-file-size-of-a-system-drawing-image

Attached you'll find code to show all metadata.
Type 0x0132 is datetime

/peter
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;

namespace SimpleTest {
  public partial class Form1 : Form {
    public Form1() {
      InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e) {
      if(openFileDialog1.ShowDialog() == DialogResult.OK) {
        textBox1.Text += openFileDialog1.FileName + Environment.NewLine;
      }
    }

    private void button2_Click(object sender, EventArgs e) {
      foreach(string filename in textBox1.Lines) {
        // Create an Image object. 
        Image image = new Bitmap(filename);

        // Get the PropertyItems property from image.
        PropertyItem[] propItems = image.PropertyItems;

        int count = 0;

        foreach(PropertyItem propItem in propItems) {
          string value = "";
          switch(propItem.Type) {
            case 1:
              value = propItem.Value[0].ToString();
              break;
            case 2:
              value = System.Text.Encoding.ASCII.GetString(propItem.Value);
              break;
            case 3:
              value = BitConverter.ToUInt16(propItem.Value, 0).ToString();
              break;
            case 4:
              value = BitConverter.ToUInt32(propItem.Value, 0).ToString();
              break;
            case 5:
              uint a1 = BitConverter.ToUInt32(propItems[count].Value, 0);
              uint b1 = BitConverter.ToUInt32(propItems[count].Value, 4);
              value = ((double)a1 / b1).ToString();
              break;
            case 9:
              // SLong
              value = Convert.ToInt32(propItem.Value).ToString();
              break;
            case 10:
              // SRational
              int a2 = BitConverter.ToInt32(propItems[count].Value, 0);
              uint b2 = BitConverter.ToUInt32(propItems[count].Value, 4);
              value = ((double)a2 / b2).ToString();
              break;

          }

          listBox1.Items.Add(String.Format("Property Item ({0}), id: 0x:{1} type: {2} length: {3} b value: {4}", count.ToString(), propItem.Id.ToString("x"),
              propItem.Type.ToString(), propItem.Len.ToString(), value
            ));
          count++;
        }
      }
    }

  }
}

Open in new window

0

Featured Post

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question