esmondb / ccr-exif

Automatically exported from code.google.com/p/ccr-exif
24 stars 11 forks source link

DataTimeOriginal returns zero date #2

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago

DateTaken := ExifData.DateTimeOriginal; returns zero date for a jpg file taken 
by Nokia N9 camera.

Also Demo VCL program ExifTimeShift Demo returns zero Original Date

Expected output is March 2nd 2012 as is shown in Windows Explorer and Google 
Picasa etc.

I'm using Delphi 2010 on Windows 7 Professional

CCR-exif is version 1.5.1

Pekka Paunio
p@sw.fi

Original issue reported on code.google.com by ppau...@gmail.com on 7 Mar 2013 at 12:31

GoogleCodeExporter commented 8 years ago
I encountered similar problem with JPEG output of some programs. 
DateTimeOriginal had needles #0 char appended at the end which confused the 
function 
TryExifStringToDateTime in CCR.Exif unit.

In my case, this simple change fixed the problem: just add Trim to Length check:

function TryExifStringToDateTime(const S: string; var DateTime: TDateTime): 
Boolean;
var
  Year, Month, Day, Hour, Min, Sec: Integer;
begin //'2007:09:02 02:30:49'
  // galfar: added Trim, some JPEGs have #0 appended to end
  Result := (Length(Trim(S)) = 19) and (S[5] = ':') and (S[8] = ':') and
    TryStrToInt(Copy(S, 1, 4), Year) and
    TryStrToInt(Copy(S, 6, 2), Month) and
    TryStrToInt(Copy(S, 9, 2), Day) and
    TryStrToInt(Copy(S, 12, 2), Hour) and
    TryStrToInt(Copy(S, 15, 2), Min) and
    TryStrToInt(Copy(S, 18, 2), Sec) and
    TryEncodeDateTime(Year, Month, Day, Hour, Min, Sec, 0, DateTime);
end; 

Original comment by marekmauder@gmail.com on 18 Jul 2013 at 12:44