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
Solved

Read Date Photo Taken Programatically vb.net

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

856 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