Solved

Read Date Photo Taken Programatically vb.net

Posted on 2011-02-23
3
861 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
Comment Utility
Meant to say I have a listing of the JPEG Files with CR LF on each line.
0
 
LVL 16

Expert Comment

by:sjklein42
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now