//======================================================================
// 機能:撮影機種名と撮影日付情報を取得する
//======================================================================
function GetPictureDate( FileName: string ): string;
var
fpR: file;
fbuf: array[0..4095] of char;
ii, jj, cnt: integer;
maker, model, pdate: string;
function GetDataI( ix:integer ): string;
var len, pos: integer;
begin
len := Ord(fbuf[ix+4]);
pos := Ord(fbuf[ix+8])+Ord(fbuf[ix+9])*$100+$C;
Result := Copy( StrPas(@fbuf[pos]),1,len );
end;
function GetDataM( ix:integer ): string;
var len, pos: integer;
begin
len := Ord(fbuf[ix+7]);
pos := Ord(fbuf[ix+10])*$100+Ord(fbuf[ix+11])+$C;
Result := Copy( StrPas(@fbuf[pos]),1,len );
end;
begin
Result := '撮影情報の取得不可';
maker := ''; model := ''; pdate := '';
AssignFile( fpR,FileName ); Reset( fpR,1 );
BlockRead( fpR, fbuf, SizeOf(fbuf) );
CloseFile( fpR );
if Copy(StrPas(@fbuf[6]),1,4)='Exif' then begin
// Exif形式のJPEGファイルなら
if (fbuf[12]='I') and (fbuf[13]='I') then begin
// インテルフォーマット
cnt := Ord( fbuf[20] );
for ii:=0 to cnt-1 do begin
jj := 12*ii + 22;
if (fbuf[jj+0]=#$0F) and (fbuf[jj+1]=#$01) then
maker := GetDataI( jj ); {メーカー情報}
if (fbuf[jj+0]=#$10) and (fbuf[jj+1]=#$01) then
model := GetDataI( jj ); {モデル情報}
if (fbuf[jj+0]=#$32) and (fbuf[jj+1]=#$01) then
pdate := GetDataI( jj ); {撮影日付情報}
end;
end;
if (fbuf[12]='M') and (fbuf[13]='M') then begin
// モトローラフォーマット
cnt := Ord( fbuf[21] );
for ii:=0 to cnt-1 do begin
jj := 12*ii + 22;
if (fbuf[jj+1]=#$0F) and (fbuf[jj+0]=#$01) then
maker := GetDataM( jj ); {メーカー情報}
if (fbuf[jj+1]=#$10) and (fbuf[jj+0]=#$01) then
model := GetDataM( jj ); {モデル情報}
if (fbuf[jj+1]=#$32) and (fbuf[jj+0]=#$01) then
pdate := GetDataM( jj ); {撮影日付情報}
end;
end;
if pdate<>'' then
Result := format( '機種=%s %s 撮影日付=%s',[maker,model,pdate] );
end;
end;
|
|
・インターネット上の情報や書籍の内容を一部参考に作成してます。 ・コーディング内容は著作権フリーですが、使用する場合は自己責任にてお願いします。 ・記述内容に問題点や改善点がありましたらこちらまでお願いします。 |