怎样获取jpeg 文件的拍摄日期 ( 积分: 200 )

虫虫2000

Unregistered / Unconfirmed
GUEST, unregistred user!
请各位高手指点一二!!
 
Q

QSmile

Unregistered / Unconfirmed
GUEST, unregistred user!
如果是数码相机照的,一般都有 Exif 信息,用 ACDSee 之类的也可以读出来,用 Exif Show 也可以
 

虫虫2000

Unregistered / Unconfirmed
GUEST, unregistred user!
能给个例子吗?
急啊!!!
 
J

japhe

Unregistered / Unconfirmed
GUEST, unregistred user!
我觉得jpeg 文件的拍摄日期可以通过创建日期或者修改日期来获取(如果要求不是很精确的话)
function GetFileTime(const AFN: string): TDateTime;
var
fh: HWND;
lpFileInfo: _BY_HANDLE_FILE_INFORMATION;
ST: TSystemTime;
{
_BY_HANDLE_FILE_INFORMATION = record
dwFileAttributes: DWORD;
//后缀名
ftCreationTime: TFileTime;
//创建时间
ftLastAccessTime: TFileTime;
//最后访问时间
ftLastWriteTime: TFileTime;
//最后修改时间
dwVolumeSerialNumber: DWORD;
nFileSizeHigh: DWORD;
nFileSizeLow: DWORD;
nNumberOfLinks: DWORD;
nFileIndexHigh: DWORD;
nFileIndexLow: DWORD;
end;
}
begin
if FileExists(AFN) then
begin
fh := FileOpen(AFN, fmOpenRead);
GetFileInformationByHandle(fh, lpFileInfo);
FileTimeToSystemTime(lpFileInfo.ftCreationTime, ST);
Result := EncodeDate(ST.wYear, ST.wMonth, ST.wDay);
FileClose(fh);
end
else
Result := 0;
end;
 

虫虫2000

Unregistered / Unconfirmed
GUEST, unregistred user!
TO:japhe,QSmile
多谢你们的答案,但我想获取的是拍摄时间,
CreateDateTime有时不一定是拍摄时间?
很急希望得到各位各位的帮忙
谢谢...
 

那年黄梅花开

Unregistered / Unconfirmed
GUEST, unregistred user!
我前几天从盒子上down了个能识别拍照时间的程序。
你可以去看看。
不过那个程序功能有限制的,比如你把拍照的相片进行缩小等处理后重新保存,就识别不出来了。(对于有些jpeg文件也识别不出来)
 
K

kaida

Unregistered / Unconfirmed
GUEST, unregistred user!
Function ReadExifDate(var sDate:string;
FileName : String) : Boolean;
Const
Numbers9 : Set of Char = ['0'..'9'];
Numbers1 : Set of Char = ['0'..'1'];
Numbers3 : Set of Char = ['0'..'3'];
Numbers5 : Set of Char = ['0'..'5'];
MaxItems = $9FF;
Var
f : File of Char;
s : String;
i,j : Integer;
a : Array[0..MaxItems] of Char;
begin
Result := False;
sDate := '';

s := '';
AssignFile(f, Filename);
Filemode := 0;
Reset(f);
For I := 0 to MaxItemsdo
begin
If not Eof(f) then
Read(f,a);
end;
CloseFile(f);
s := a[6] + a[7] + a[8] + a[9];
If ANSIUppercase(s) = 'EXIF' then

Result := True
else
Exit;
For I := 10 to MaxItems - 15do
begin
If a = ':' then
begin
s := '';
For j := 0 to 18do
s := s + a[i + j - 4];
If(s[01] in Numbers9) and (s[02] in Numbers9) and
(s[03] in Numbers9) and (s[04] in Numbers9) and
(s[05] = ':') and
(s[06] in Numbers1) and (s[07] in Numbers9) and
(s[08] = ':') and
(s[09] in Numbers3) and (s[10] in Numbers9) and
(s[11] = ' ') and
(s[12] in Numbers5) and (s[13] in Numbers9) and
(s[14] = ':') and
(s[15] in Numbers5) and (s[16] in Numbers9) and
(s[17] = ':') and
(s[18] in Numbers5) and (s[19] in Numbers9) then
begin
sDate := s;
If sDate = '0000:00:00 00:00:00' then
ShowMessage('无效日期时间!');
Exit;
end;
end;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
sDate: String;
begin
OpenDialog1.Filter := 'JPEG files|*.jpg;*.jpeg';
if OpenDialog1.Execute then
begin
if ReadExifDate(sDate, OpenDialog1.FileName) then
Caption:=sDate
else
Caption:='没有时间信息';
end;
end;
 
K

kaida

Unregistered / Unconfirmed
GUEST, unregistred user!
注意,不是任何 jpg 文件都有 Exif。上面代码只对有 Exif 的 jpg 文件(例如数码相机拍摄的未经处理的 jpg 文件)。
 
A

angellover

Unregistered / Unconfirmed
GUEST, unregistred user!

虫虫2000

Unregistered / Unconfirmed
GUEST, unregistred user!
多人接受答案了。
 
Top Bottom