![]() |
also dann.. ich hab mich mal hingesetzt und schnell was für dich zusammengeschustert:
Code:
so, jetzt hast du in den Variablen Width und Height die Breite und die Höhe des GIF-Bilds (sofern es ein GIF89-konformes GIF ist ;))
[b]procedure[/b] TForm1.Button1Click(Sender: TObject);
[b]var[/b] gif: integer; dmy: [b]array[/b][0..3] [b]of[/b] Char; Width, Height: integer; [b]begin[/b] gif := FileOpen('blabla.gif'); FileSeek(gif, 6, 0); [color=#000080][i]//<- man könnte hier noch testen, ob // davor der GIF-Tag in der Datei // steht..[/i][/color] FileRead(Gif,dmy,4); FileCLose(gif); Width := ord(dmy[1]) * 256 + ord(dmy[0]); [color=#000080][i]//<- die hex-werte umwandeln[/i][/color] Height := ord(dmy[3]) * 256 + ord(dmy[2]); [b]end[/b]; Ich hoffe, das hilft dir weiter.. Der Code prüft übrigens nicht, ob's sich bei der datei wirklich um ein GIF handelt, dazu brauchst du aber nur testen, ob die ersten 3 bzw. 5 bytes 'GIF' bzw. 'GIF89' sind ;) greetz, -movax- | ![]() |
@movax: Ich bin mir sicher: Tpercon wirds danken. :)
:cat: |
Danke sakura für die Erklärung! Und natürlich auch an movax ein Danke.
Dann werde ich fürs jpeg wohl nicht drum rum kommen, die Unit jpeg (macht das Prog ca. 90 kB größer :( ) mit einzubinden. Hat jemand sonst zu den anderen Formaten (.png) ne Idee oder so ne gute Erklärung? |
Hi
Die Breiten und Höhenangabe steht beim Icon beim 6. und 7. Byte, beim png vom 16.- 19. und 20. - 23. Byte. Beim jpeg muß da doch auch irgend ne Regelmäßigkeit sein?! |
Eine Regelmäßigkeit gibts schon, aber die hat ein paar verschiedene Abhängigkeiten...
Code:
Das heisst, Du musst zuerst das Segment finden, welches mit dem Marker 0xFFC0 markiert ist, und das muss nicht das erste Segment sein, da dort auch andere Informationen gespeichert sein können. in diesem Segment musst Du Byte 5 und 6 für die Höhe lesen und Byte 7 und 8 für die Breite.
JPEG/JFIF file format:
~~~~~~~~~~~~~~~~~~~~~~ - header (2 bytes): $ff, $d8 (SOI) (these two identify a JPEG/JFIF file) - for JFIF files, an APP0 segment is immediately following the SOI marker, see below - any number of "segments" (similar to IFF chunks), see below - trailer (2 bytes): $ff, $d9 (EOI) Segment format: ~~~~~~~~~~~~~~~ - header (4 bytes): $ff identifies segment n type of segment (one byte) sh, sl size of the segment, including these two bytes, but not including the $ff and the type byte. Note, not Intel order: high byte first, low byte last! - contents of the segment, max. 65533 bytes. Notes: - There are parameterless segments (denoted with a '*' below) that DON'T have a size specification (and no contents), just $ff and the type byte. - Any number of $ff bytes between segments is legal and must be skipped. Segment types: ~~~~~~~~~~~~~~ *TEM = $01 usually causes a decoding error, may be ignored SOF0 = $c0 Start Of Frame (baseline JPEG), for details see below SOF1 = $c1 dito SOF2 = $c2 usually unsupported SOF3 = $c3 usually unsupported SOF5 = $c5 usually unsupported SOF6 = $c6 usually unsupported SOF7 = $c7 usually unsupported SOF9 = $c9 for arithmetic coding, usually unsupported SOF10 = $ca usually unsupported SOF11 = $cb usually unsupported SOF13 = $cd usually unsupported SOF14 = $ce usually unsupported SOF14 = $ce usually unsupported SOF15 = $cf usually unsupported DHT = $c4 Define Huffman Table, for details see below JPG = $c8 undefined/reserved (causes decoding error) DAC = $cc Define Arithmetic Table, usually unsupported *RST0 = $d0 RSTn are used for resync, may be ignored *RST1 = $d1 *RST2 = $d2 *RST3 = $d3 *RST4 = $d4 *RST5 = $d5 *RST6 = $d6 *RST7 = $d7 SOI = $d8 Start Of Image EOI = $d9 End Of Image SOS = $da Start Of Scan, for details see below DQT = $db Define Quantization Table, for details see below DNL = $dc usually unsupported, ignore SOI = $d8 Start Of Image EOI = $d9 End Of Image SOS = $da Start Of Scan, for details see below DQT = $db Define Quantization Table, for details see below DNL = $dc usually unsupported, ignore DRI = $dd Define Restart Interval, for details see below DHP = $de ignore (skip) EXP = $df ignore (skip) APP0 = $e0 JFIF APP0 segment marker, for details see below APP15 = $ef ignore JPG0 = $f0 ignore (skip) JPG13 = $fd ignore (skip) COM = $fe Comment, for details see below All other segment types are reserved and should be ignored (skipped). SOF0: Start Of Frame 0: ~~~~~~~~~~~~~~~~~~~~~~~ - $ff, $c0 (SOF0) - length (high byte, low byte), 8+components*3 - data precision (1 byte) in bits/sample, usually 8 (12 and 16 not supported by most software) - image height (2 bytes, Hi-Lo), must be >0 if DNL not supported - image width (2 bytes, Hi-Lo), must be >0 if DNL not supported - number of components (1 byte), usually 1 = grey scaled, 3 = color YCbCr or YIQ, 4 = color CMYK) - for each component: 3 bytes - component id (1 = Y, 2 = Cb, 3 = Cr, 4 = I, 5 = Q) - sampling factors (bit 0-3 vert., 4-7 hor.) - quantization table number
Code:
:cat:
NOTE: The JPEG/JFIF file format uses Motorola format for words, NOT Intel format,
i.e. : high byte first, low byte last -- (ex: the word FFA0 will be written in the JPEG file in the order : FF at the low offset , A0 at the higher offset) |
Hi
Kann das sein, dass jpeg Dateien FFC2 haben und jpg FFC0? So ist das nämlich bei den Dateien bei mir!? Wenn das immer so wäre, dann kann ich die jetzt auch erfolgreich auslesen. Gruß |
Eigentlich sollte es nicht so sein, aber wer weiss... Am besten erst nach 0xFFC0 suchen, und wenn es dieses nicht gibt nach 0xFFC2... Theoretisch kommt JPEG daher, dass seit Win95 die Dateiendung nicht mehr auf 3 Zeichen begrenzt ist und seit dem auch UNIX Dateinamen funktionieren...
|
Habt ihr den jpeg Dateien wo das nicht C2 ist?
|
Moin Tpercon,
also auf Dateiendungen würde ich mich prinzipiell nicht verlassen. Zur exakten Feststellung des Dateityps sind i.d.R. die Headerinformationen in Dateien die diese bieten gedacht. |
Prinzipiell hast du natürlich recht!
Die ersten 10 Byte's sind bei beiden gleich. Mich würde es halt trotzdem interessieren. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:50 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz