exif data from jpg's

C

CowDev

Can someone please enlighten me on how to retrieve exif data from jpg's using
vba? My app reads job photos and their path from a specified folder and adds
the file and path data to a photos table where the user can add captions etc.


The app also creates a copy of each photo much smaller in size yet suitable
for documentation, printing, and the transfer of the job file to other users.

I need to get at the "Date Picture Taken" property since the file creation
date is useless once the new, lower-res photo is created.

I have searched and searched for answers to my dilema with not much luck. I
understand that installing the new Windows Desktop Search utility would make
the exif data accessible however, I will not force my users to install it.

Thanks in advance.
 
A

Albert D. Kallal

There is some sample VB6 code here that should work just fine in access

http://www.vbaccelerator.com/home/V...g_EXIF_and_Other_Image_Properties/article.asp

I assume you have some code to already read the list of files in a
directory?

Here is some code that will traverse a directory structure, and give you a
"collection" of files;

Sub dirTest()

Dim dlist As New Collection
Dim startDir As String
Dim i As Integer

startDir = "C:\access\"
Call FillDir(startDir, dlist)

MsgBox "there are " & dlist.Count & " in the dir"

' lets printout the stuff into debug window for a test

For i = 1 To dlist.Count
Debug.Print dlist(i)
Next i

End Sub


Sub FillDir(startDir As String, dlist As Collection)

' build up a list of files, and then
' add add to this list, any additinal
' folders

Dim strTemp As String
Dim colFolders As New Collection
Dim vFolderName As Variant

strTemp = Dir(startDir)

Do While strTemp <> ""
dlist.Add startDir & strTemp
strTemp = Dir
Loop

' now build a list of additional folders
strTemp = Dir(startDir & "*.", vbDirectory)

Do While strTemp <> ""
If (strTemp <> ".") And (strTemp <> "..") Then
colFolders.Add strTemp
End If
strTemp = Dir
Loop

' now process each folder (recursion)
For Each vFolderName In colFolders
Call FillDir(startDir & vFolderName & "\", dlist)
Next vFolderName

End Sub

And, for prompting to open a file bowerse dialog:
file open dialog:
http://www.mvps.org/access/api/api0001.htm

browse to folder open dialog:
http://www.mvps.org/access/api/api0001.htm

Between all of the above links, you should be able cobble together some code
in which clicking a button can browses to a folder, then reads in the list
of file names, and then reads the tags (exif) info into a database if you so
need.......
 
C

CowDev

Thanks for the quick reply Albert. I did come across that sample code in my
searches. However, I am unfamiliar with incorporating vb6 .cls files into MS
Access (2003) and have not found any tutorials for doing this. Can you
assist.

jim
 
A

Albert D. Kallal

Thanks for the quick reply Albert. I did come across that sample code in
my
searches. However, I am unfamiliar with incorporating vb6 .cls files into
MS
Access (2003) and have not found any tutorials for doing this. Can you
assist.

jim

Sure, I just tried this...and it works like a charm.....

Simply unzip the download.

Now, in the folder, simply open up that file called ExifReader.cls

If you have vb6 installed, it will see it appear as a VB6 class icon, and if
you double click on the file (ExifReader.cls), then the
VB6 development system and editor will launch when you click on it.

If you do NOT have vb6 installed, then when you click on the file
(ExifReader.cls), then you be asked to choose an web service, or the 2nd
option of select the program from a list. (use the 2nd option)

application to open it with

(use notepad) .

When you open the text document, simply place the cursor on the first line,
hold down the shift key, and start hitting the down arrow key.
We need to highlight up to the line:

Option Explicit.

(it is aout 16 lines you have to hight lit)...now, hit the delete key).

If you had vb6 insalled, the first junk would be removed for you..and you
simply cut/paste the code...

So, we delete all stuff up to the line Option Explicit.

Now, go edit->select all.

now edit->copy

We now are now going to paste this code into a ms-accesss CLASS OBJECT
modulete..

Open up the access appcation were you going to use this code.

from the main menu, go

insert->class module

You see:

Option Compare Database
Option Explicit

move your cusor below the above two lines (you might not have the Option
Expclit, but that somtong you should have set in the tools->otipons...we fix
that later).

Now, edit->paste in your code

(if you copied the Option Explit..hten we have it two times...delete one of
them)

now, save (hit the save buttion on teh code editor menu).

THIS NAME we going to give the module will become the name of this class
object code we just pasted.

lets call it

clsExif

After you save it, you should do a debug->compile...make sure all your code
compiles....

Now, in one of your standard code modules, or forms, lets do a test of this
code:

Sub testread()

Dim clsPic As New clsExif

clsPic.picFile = "c:\1.jpg"
Debug.Print clsPic.Tag(ExifImageHeight)
Debug.Print clsPic.Tag(ExifImageWidth)
Debug.Print clsPic.Tag(DateTime)


End Sub

When I run the above, I get:

2304
3072
2007:10:22 19:41:10

I using a 7.2 mp digital camera...

Of course, that means I have a picture called 1.jpg in c:\ (in the root
directory).

Note that I never used this before, but intel-sense WILL show you the "list"
of appropriate volutes in the tag function when you hit the "("...if it does
not , then try pressing ctrl-j...it should pop a list of possible values.
This intel-sense ONLY works if you have no compile errors in your code...

I did the above as I typed these instructions...and it worked the first
time.

It is a nice routine ...and I will save it...as I also have need for a jpeg
picture reading routine....
 
C

CDev

Albert

Once again, your assistance has been greatly appreciated!

In addition to your instruction below, I had to do the following:
- Add the text in the IFDData.cls file to a new Class Module in my Access
2003 app.
- Change clsPic.picFile = "c:\1.jpg" to clsPic.Load "c:\1.jpg"
- Use clsPic.Tag(DateTimeOriginal) to get the Date Picture Taken value.

clsPic.picFile = "c:\1.jpg" returns the compile error "Method or data member
not found." '.picFile' is not a valid value so I selected '.Load'. Is this
the most efficient way. It seems to me I read that this information can be
retrieved with out "Loading" the whole file. I really don't think this will
be an issue but it would be nice to know that I'm accomplishing the task with
the least amount of resources.

Thanks again, Albert.
 
A

Albert D. Kallal

CDev said:
Albert

Once again, your assistance has been greatly appreciated!

In addition to your instruction below, I had to do the following:
- Add the text in the IFDData.cls file to a new Class Module in my Access
2003 app.

I don't know where the above IFDDdata.cls file comes from. You don't need
it.

The download I was
talking about is here:

http://sourceforge.net/projects/exifclass/

From the above, the zip file reuslts in TWO files

ExifReader.cls

and

Readme.txt

You simply do the cut/paste into a new "class", module, and you should be
fine.

- Change clsPic.picFile = "c:\1.jpg" to clsPic.Load "c:\1.jpg"

Yes, that seems like a mistake on my part (sorry).

I suggest you use load aways...
Tag(DateTimeOriginal)

I not looked as to what the difference is between DateTime, and Datetime
Original......

I suspect this will depend on the original camera...and how it is setup....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top