Welcome to MSDN Blogs Sign in | Join | Help

Timestamp digital pictures

I was given several dozen digital photos that I wanted to add to my collection. However, the camera used did not have the date/time set. Worst still, each time the camera was turned on, the camera clock started ticking from the same time (1/1/2004 midnight).

 

With certain display modes of my picture display program and screen saver, the pictures are sorted by date/time stamp order. However, because these pictures were from several events, the pictures appeared to be in a random order. In fact, they were in date/time order, so the first picture displayed was the one closest to the time of the camera power on, and the last was the one with the camera on the longest.

 

I wrote a simple program to adjust the file timestamps to be at least in chronological order based on the picture sequence number, which was chronological. Of course, this did not change the Exif JPG picture properties directly stored inside the JPG file.

 

See also:

Draw text or graphics directly onto a JPG file

Sharing Digital Pictures of your friend's

Make an interactive screen saver

 

 

 

n=ADIR(aa,cPath+"*.*")

ASORT(aa,1,n)

FOR i = 1 TO n

          retimestamp(cPath+aa[i,1],CTOT("11/27/06")+i*3600)

          ?aa[i,1],aa[i,3],aa[i,4]

ENDFOR

RETURN

 

 

 

*From WINNT.H:

#define FILE_SHARE_READ                 0x00000001 

#define FILE_SHARE_WRITE                0x00000002 

#define FILE_SHARE_DELETE               0x00000004 

#define FILE_ATTRIBUTE_READONLY             0x00000001 

#define FILE_ATTRIBUTE_HIDDEN               0x00000002 

#define FILE_ATTRIBUTE_SYSTEM               0x00000004 

#define FILE_ATTRIBUTE_DIRECTORY            0x00000010 

#define FILE_ATTRIBUTE_ARCHIVE              0x00000020 

#define FILE_ATTRIBUTE_DEVICE               0x00000040 

#define FILE_ATTRIBUTE_NORMAL               0x00000080 

#define FILE_ATTRIBUTE_TEMPORARY            0x00000100 

#define FILE_ATTRIBUTE_SPARSE_FILE          0x00000200 

#define FILE_ATTRIBUTE_REPARSE_POINT        0x00000400 

#define FILE_ATTRIBUTE_COMPRESSED           0x00000800 

#define FILE_ATTRIBUTE_OFFLINE              0x00001000 

#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED  0x00002000 

#define FILE_ATTRIBUTE_ENCRYPTED            0x00004000 

#define FILE_WRITE_ATTRIBUTES                                0x100

#define GENERIC_WRITE     (0x40000000)

#define GENERIC_READ      (0x80000000)

 

 

*From winbase.h:

#define CREATE_NEW          1

#define CREATE_ALWAYS       2

#define OPEN_EXISTING       3

#define OPEN_ALWAYS         4

#define TRUNCATE_EXISTING   5

 

PROCEDURE ReTimeStamp(cFilename as string, dt as Datetime)

                   DECLARE integer CreateFile in win32api string, integer dwDesiredAccess, integer dwShareMode, integer security, ;

                             integer dwCreationDisposition, integer FlagsAttrs, integer hTemplate

                   DECLARE INTEGER CloseHandle in win32api integer hFile

                   DECLARE integer SystemTimeToFileTime IN WIN32API string , string @

                   DECLARE INTEGER SetFileTime IN kernel32;

                             INTEGER hFile, STRING lpCreationTime,;

                             STRING lpLastAccessTime, STRING lpLastWriteTime

                   DECLARE INTEGER SystemTimeToFileTime IN kernel32;

                             STRING lpSystemTime, STRING @lpFileTime

                   DECLARE INTEGER LocalFileTimeToFileTime IN kernel32;

                             STRING lpLocalFileTime, STRING @lpFileTime

                   DECLARE integer GetLastError in win32api

 

                   cFileTime = SPACE(8)

                   cSysTime=BINTOC(YEAR(dt),"2rs") + ;

                                      BINTOC(MONTH(dt),"2rs") + ;

                                      BINTOC(DOW(dt,0),"2rs") + ;

                                      BINTOC(DAY(dt),"2rs") + ;

                                      BINTOC(HOUR(dt),"2rs") + ;

                                      BINTOC(MINUTE(dt),"2rs") + ;

                                      REPLICATE(CHR(0),4)

                   SystemTimeToFileTime(cSysTime, @cFileTime)

 

                   LocalFileTimeToFileTime(cFileTime, @cFileTime)

 

                   hFile = CreateFile(cFilename, GENERIC_WRITE+GENERIC_READ,FILE_SHARE_READ, 0, OPEN_EXISTING, 0,0)

                   SetFileTime(hFile , cFileTime, cFileTime,cFileTime)

                   CloseHandle(hFile)

 

RETURN

 

Published Monday, December 04, 2006 8:06 PM by Calvin_Hsia
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Timestamp digital pictures

Tuesday, December 05, 2006 1:34 AM by Tom

this program is great for fixing the timestamps in the EXIF headers of JPEG files:

http://www.sentex.ca/~mwandel/jhead/

# re: Timestamp digital pictures

Thursday, February 01, 2007 7:50 PM by Bryan Wetton

Very Interested in your routine.

In VFP6 compiling the routine as printed throws up errors.

Am I doing something wrong?

Regards

Bryan

# Compress and timestamp your pictures to gain disk space

Thursday, March 13, 2008 4:24 PM by Calvin Hsia's WebLog

I was running out of space again on my notebook. As years go by, digital cameras can take pictures with

# Compress and timestamp your pictures to gain disk space

Thursday, March 13, 2008 5:15 PM by Noticias externas

I was running out of space again on my notebook. As years go by, digital cameras can take pictures with

# Good site

Friday, July 04, 2008 5:38 AM by Olgunka-ta

<a href= http://index3.tsopol.com >xxxalbum</a> <a href= http://index1.tsopol.com >female muslim doctor threatened with death for disputing koran teachings</a> <a href= http://index5.tsopol.com >glass telephones</a> <a href= http://index4.tsopol.com >cockroaches in apartments</a> <a href= http://index2.tsopol.com >vacume line scamatic for 1969 grand torino</a>

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker