1
votes

I am writing a program in Delphi which should get the date and time of the picture which was taken with photo cam and then it would rename the file to include the date+time it found.

So far i have achieved that by opening file as binary and searching for a special order of bytes. These bytes were then followed by the date and then time. So i've come to a problem. Actually few problems.

  1. Because it reads the file 1 byte after another, reading a file is a slow process. If the date was found, it is usually at the start of file, it doesn't take long, however if 'special byte order' was not found, it will read the whole file. So my method is way too slow.

  2. The special byte order may change in some pictures (i have no idea why) even if it was taken with the same camera. So my program sometimes fails to find the date in the file even though it is there.

Windows explorer has no problems finding date in all of the pictures, so i was thinking maybe there are some kind of special functions which could get me what i need?

How do i get the information i need from the picture so it works with all the formats?

Thanks

4
You're readingt the file 1 byte at at time from the disk? Why not read the whole file into a buffer then process it there?Rup
yes, why don't you read the whole picture into the memory and process it then? by the way there are loads of picture format descriptions out there, you would only need to find the header of the picture formats that you want to support and read the header(which usually tells you where the date and time are located) from the file.user497849
keywords: EXIF, IPTC and DPOF maybeFree Consulting

4 Answers

5
votes

I think you only need to look at the EXIF information. http://en.wikipedia.org/wiki/Exif

There are some open source tools which accomplish that, but I don't know of anything Delphi specific. If you're not scared of Java, you can have a look at the source code of this open source project: http://sourceforge.net/projects/jexifviewer/ to see how they evaluate the date field.
You can then optimise your reader, to only look at the relevant area. You might want to keep in mind that the Endianness in Java is different to Delphi.

5
votes

Jules is right about Exif data; you might want to try this Delphi library:

http://delphihaven.wordpress.com/ccr-exif/

0
votes

This is an amazing site to view Exif data.

http://regex.info/exif.cgi

0
votes

If it is a graphic file (as in your case), to open it with a dialog box, place a TOpenPictureDialog component on the form. Also place the component TLabel, for displaying the date of creation of the file. In the button's place the following code:

if OpenPictureDialog1.Execute then Label1.Caption := DateTimeToStr(FileDateToDateTime(FileAge(OpenPictureDialog1.FileName));

In order to open jpeg and png files in the code, in the line uses you need to add the name of the two libraries, JPEG, PNGImage.

If you have the full address of your file, you can write the code above instead of the code above:

Label1.Caption := DateTimeToStr(FileDateToDateTime(FileAge('full address to file')));

If you only need the date, without the file creation time, then instead of the DateTimeToStr command, use the DateToStr command.