Autor Beitrag
hansschranz
Hält's aus hier
Beiträge: 7



BeitragVerfasst: Mi 12.01.05 18:16 
hallo bin ganz neu hier und möchte ersteinmal sagen wie toll dieses forum ist.

ich möchte ein programm schreiben mit dem ich die exifdaten aus jpegdateien auslesen kann. habe mich hier auch schon schlau gemacht und gesehen, dass mann unter www.torry.net eine unit names texif runterladen kann habe dies auch getan. allerdibgs wenn ich diese jetzt einbinde und darauf zugreifen will bekomme ich immer eine "Eaccessviolation". ich kann mit diesen fehlermeldungen immer nichts anfangen aber accesss ist ja zugriff also scheint es ja eine art zugrifss fehler zu sein. hoffe mir kann jemand helfen.

hier nochmal meine unit


ausblenden unit1
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Exif;

...

var
  Form1: TForm1;
  Daten: Texif;

..

procedure TForm1.Button1Click(Sender: TObject);
begin
TExif.Create;
opendialog1.Execute;
Daten.ReadFromFile(opendialog1.FileName);
end;

end.




ausblenden volle Höhe Exif-Unit
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;     //Picture description
      FMake               : String;     //Camera manufacturer
      FModel              : String;     //Camere model
      FOrientation        : Byte;       //Image orientation - 1 normal
      FOrientationDesk    : String;     //Image orientation description
      FCopyright          : String;     //Copyright
      FValid              : Boolean;    //Has valid Exif header
      FDateTime           : String;     //Date and Time of Change
      FDateTimeOriginal   : String;     //Original Date and Time
      FDateTimeDigitized  : String;     //Camshot Date and Time
      FUserComments       : String;     //User Comments

      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;      //Section marker
    Len      : Word;      //Length Section
    Indefin  : Array [0..4of Char; //Indefiner - "Exif" 00, "JFIF" 00 and ets
    Pad      : Char;      //0x00
  end;

  TTag = record
    TagID   : Word;       //Tag number
    TagType : Word;       //Type tag
    Count   : Cardinal;   //tag length
    OffSet  : Cardinal;   //Offset / Value
  end;

  TIFDHeader = record
    pad          : Byte; //00h
    ByteOrder    : Word; //II (4D4D)
    i42          : Word; //2A00
    IFD0offSet   : Cardinal; //0th offset IFD
    Interoperabil: Byte;
  end;

function TExif.ReadValue(const Offset, Count: Cardinal): String;
var fp: LongInt;
     i: Word;
begin
  SetLength(Result,Count);
  fp:=FilePos(f); //Save file offset
  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;
//  Result:=TrimRight(Result);
  Seek(f,fp);     //Restore file offset
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..8of 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; //Null Exif Offset
  tag: TTag;
    i: Integer;
  SOI: Word; //2 bytes SOI marker. FF D8 (Start Of Image)

begin
  if not FileExists(FileName) then exit;
  Init;

  AssignFile(f,FileName);
  reset(f,1);

  BlockRead(f,SOI,2);
  if SOI=$D8FF then begin //Is this Jpeg
    BlockRead(f,j,9);

    if j.Marker=$E0FF then begin //JFIF Marker Found
      Seek(f,20); //Skip JFIF Header
      BlockRead(f,j,9);
    end;

    if j.Marker=$E1FF then begin //If we found Exif Section. j.Indefin='Exif'.
      FValid:=True;
      off0:=FilePos(f)+1;   //0'th offset Exif header
      BlockRead(f,idf,11);  //Read IDF Header

      i:=0;
      repeat
        inc(i);
        BlockRead(f,tag,12);
        //0E01 ImageDescription
        if tag.TagID=$010E then FImageDesc:=ReadValue(tag.OffSet+off0,tag.Count);
        //0F01 Make
        if tag.TagID=$010F then FMake:=ReadValue(tag.OffSet+off0,tag.Count);
        //1001 Model
        if tag.TagID=$0110 then FModel:=ReadValue(tag.OffSet+off0,tag.Count);
        //6987 Exif IFD Pointer
        if tag.TagID=$8769 then idfp:=Tag.OffSet; //Read Exif IDF offset
        //1201 Orientation
        if tag.TagID=$0112 then begin
           FOrientation:=tag.OffSet;
           if tag.OffSet in [1..8then FOrientationDesk:=ori[tag.OffSet] else FOrientationDesk:='Unknown';
        end;
        //3201 DateTime
        if tag.TagID=$0132 then FDateTime:=ReadValue(tag.OffSet+off0,tag.Count);
        //9882 CopyRight
        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);//12 - Size header before Exif, 2 - size Exif IFD Number
        i:=0;
        repeat
          inc(i);
          BlockRead(f,tag,12);
  {
          You may simple realize read this info:

          tag |Name of tag

          9A82 ExposureTime
          9D82 FNumber
          0090 ExifVersion
          0390 DateTimeOriginal
          0490 DateTimeDigitized
          0191 ComponentsConfiguration
          0292 CompressedBitsPerPixel
          0192 ShutterSpeedValue
          0292 ApertureValue
          0392 BrightnessValue
          0492 ExposureBiasValue
          0592 MaxApertureRatioValue
          0692 SubjectDistance
          0792 MeteringMode
          0892 LightSource
          0992 Flash
          0A92 FocalLength
          8692 UserComments
          9092 SubSecTime
          9192 SubSecTimeOriginal
          9292 SubSecTimeDigitized
          A000 FlashPixVersion
          A001 Colorspace
          A002 Pixel X Dimension
          A003 Pixel Y Dimension
  }


          //0390 FDateTimeOriginal
          if tag.TagID=$9003 then FDateTimeOriginal:=ReadValue(tag.OffSet+off0,tag.Count);
          //0490 DateTimeDigitized
          if tag.TagID=$9004 then FDateTimeDigitized:=ReadValue(tag.OffSet+off0,tag.Count);
          //8692 UserComments
          if tag.TagID=$9286 then FUserComments:=ReadValue(tag.OffSet+off0,tag.Count);
        until (i>23);
      end;
    end;
  end;
  CloseFile(f);
end;

end




Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt.
Timosch
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1314

Debian Squeeze, Win 7 Prof.
D7 Pers
BeitragVerfasst: Mi 12.01.05 18:20 
Zitat:
TExif.Create

Ich weiß nicht ob das so geht, eigentlich dürfte es das nicht.
ausblenden Delphi-Quelltext
1:
daten:=TExif.Create					

So sollte es gehen.

Korrigiert mich, wenn ich was falsches sage.

_________________
If liberty means anything at all, it means the right to tell people what they do not want to hear. - George Orwell
hansschranz Threadstarter
Hält's aus hier
Beiträge: 7



BeitragVerfasst: Mi 12.01.05 20:07 
besten dank für die schnelle hilfe hier funktioniert super ihr seid echt die besten
:D
hansschranz Threadstarter
Hält's aus hier
Beiträge: 7



BeitragVerfasst: Mi 19.01.05 02:48 
so nun leider noch ein weiteres problem benötige die daten mit dem tagnamen keyword und object name allerdings gehören diese zu iptc und nicht mehr in den exif teil glaube ich, dass heisst der file pointer muss glaube ich weiter gesetzt werden aber weiss nicht genau wie dat funzt also ich benutze immer noch die oben gepostete exif unit und möchte es dort in der funktion readfromfile einfügen danke schon mal im voraus
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 19.01.05 04:12 
Neue Frage, neuer Thread bitte.