Solved

Read Date Photo Taken Programatically vb.net

Posted on 2011-02-23
3
874 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
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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