1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218:
| unit Exif;
interface
uses Classes, SysUtils;
type TExif = class(TObject) private FImageDesc : String; FMake : String; FModel : String; FOrientation : Byte; FOrientationDesk : String; FCopyright : String; FValid : Boolean; FDateTime : String; FDateTimeOriginal : String; FDateTimeDigitized : String; FUserComments : String; f : File; idfp : Cardinal; function ReadValue(const Offset, Count: Cardinal): String; procedure Init; public constructor Create; procedure ReadFromFile(const FileName: AnsiString);
property ImageDesc: String read FImageDesc; property Make: String read FMake; property Model: String read FModel; property Orientation: Byte read FOrientation; property OrientationDesk: String read FOrientationDesk; property Copyright: String read FCopyright; property Valid: Boolean read FValid; property DateTime: String read FDateTime; property DateTimeOriginal: String read FDateTimeOriginal; property DateTimeDigitized: String read FDateTimeDigitized; property UserComments: String read FUserComments; end;
implementation
type TMarker = record Marker : Word; Len : Word; Indefin : Array [0..4] of Char; Pad : Char; end;
TTag = record TagID : Word; TagType : Word; Count : Cardinal; OffSet : Cardinal; end;
TIFDHeader = record pad : Byte; ByteOrder : Word; i42 : Word; IFD0offSet : Cardinal; Interoperabil: Byte; end;
function TExif.ReadValue(const Offset, Count: Cardinal): String; var fp: LongInt; i: Word; begin SetLength(Result,Count); fp:=FilePos(f); Seek(f, Offset); try i:=1; repeat BlockRead(f,Result[i],1); inc(i); until (i>=Count) or (Result[i-1]=#0); if i<=Count then Result:=Copy(Result,1,i-1); except Result:=''; end; Seek(f,fp); end;
procedure TExif.Init; begin
idfp:=0;
FImageDesc:=''; FMake:=''; FModel:=''; FOrientation:=1; FOrientationDesk:='Normal'; FDateTime:=''; FCopyright:=''; FValid:=False; FDateTimeOriginal:=''; FDateTimeDigitized:=''; FUserComments:=''; end;
constructor TExif.Create; begin Init; end;
procedure TExif.ReadFromFile(const FileName: AnsiString); const ori: Array[1..8] of String=('Normal','Mirrored','Rotated 180','Rotated 180, mirrored','Rotated 90 left, mirrored','Rotated 90 right','Rotated 90 right, mirrored','Rotated 90 left'); var j: TMarker; idf: TIFDHeader; off0: Cardinal; tag: TTag; i: Integer; SOI: Word; begin if not FileExists(FileName) then exit; Init;
AssignFile(f,FileName); reset(f,1);
BlockRead(f,SOI,2); if SOI=$D8FF then begin BlockRead(f,j,9);
if j.Marker=$E0FF then begin Seek(f,20); BlockRead(f,j,9); end;
if j.Marker=$E1FF then begin FValid:=True; off0:=FilePos(f)+1; BlockRead(f,idf,11); i:=0; repeat inc(i); BlockRead(f,tag,12); if tag.TagID=$010E then FImageDesc:=ReadValue(tag.OffSet+off0,tag.Count); if tag.TagID=$010F then FMake:=ReadValue(tag.OffSet+off0,tag.Count); if tag.TagID=$0110 then FModel:=ReadValue(tag.OffSet+off0,tag.Count); if tag.TagID=$8769 then idfp:=Tag.OffSet; if tag.TagID=$0112 then begin FOrientation:=tag.OffSet; if tag.OffSet in [1..8] then FOrientationDesk:=ori[tag.OffSet] else FOrientationDesk:='Unknown'; end; if tag.TagID=$0132 then FDateTime:=ReadValue(tag.OffSet+off0,tag.Count); if tag.TagID=$8298 then FCopyright:=ReadValue(tag.OffSet+off0,tag.Count); until (i>11);
if idfp>0 then begin Seek(f,idfp+12+2); i:=0; repeat inc(i); BlockRead(f,tag,12);
if tag.TagID=$9003 then FDateTimeOriginal:=ReadValue(tag.OffSet+off0,tag.Count); if tag.TagID=$9004 then FDateTimeDigitized:=ReadValue(tag.OffSet+off0,tag.Count); if tag.TagID=$9286 then FUserComments:=ReadValue(tag.OffSet+off0,tag.Count); until (i>23); end; end; end; CloseFile(f); end;
end |