Autor Beitrag
walter_b
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 135

Windows Vista/XP
Delphi 6
BeitragVerfasst: Di 12.05.09 09:39 
Hello world!

Ich stehe vor folgendem Problem: Ich habe eine Console Application und möchte dort die Höhe und die Breite eines PNG-Bildes einlesen, allerdings habe ich keine Ahnung, wie ich das hinkriege.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
     
var
  F : text;
  s : string;

[...]

  write('Input file name to read : '); readln(s);
  assign(F,s);
  reset(F);
  while not EOF(F) do
  begin
    readln(F,s);
    writeln(s);
  end;
  close(F);



So habe ich es bisher versucht, jedoch kann das Programm das Bild natürlich nicht als Textdatei lesen, bzw. es wird nur "ëPNG" ausgegeben. Wie muss ich das anstellen?

Vielen Dank!
Reinhard Kern
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 591
Erhaltene Danke: 14



BeitragVerfasst: Di 12.05.09 09:45 
user profile iconwalter_b hat folgendes geschrieben Zum zitierten Posting springen:
Hello world!

Ich stehe vor folgendem Problem: Ich habe eine Console Application und möchte dort die Höhe und die Breite eines PNG-Bildes einlesen...


Hallo,

die nötigen Infos über das PNG-Format findest du u.a. hier:

www.libpng.org/pub/p...G-Chunks.html#C.IHDR

Gruss Reinhard
walter_b Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 135

Windows Vista/XP
Delphi 6
BeitragVerfasst: Di 12.05.09 10:01 
Vielen Dank für den Link. Ich habe mir mal einen Überblick verschafft, jedoch alles was ich gefunden habe, ist, dass im IHDR-Teil des PNG die Informationen sind, die ich brauche. Doch wie bringe ich diese Infos raus? Habe leider keine Idee, wie ich das angehen könnte.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Di 12.05.09 10:49 
Wer sagt, dass Du die PNG-Komponenten\Klassen nicht auch in einer Konsolen-Anwendung nutzen kannst?

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
walter_b Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 135

Windows Vista/XP
Delphi 6
BeitragVerfasst: Di 12.05.09 13:15 
hm... ich steh wohl gerade voll auf der Leitung... Wie soll ich denn die PNG-Komponenten benützen, bzw. ansprechen?

---Moderiert von user profile iconNarses: Beiträge zusammengefasst---

Ok, hat sich erledigt, habe es auf eine andere Art lösen können.
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Di 12.05.09 15:21 
user profile iconwalter_b hat folgendes geschrieben Zum zitierten Posting springen:
Ok, hat sich erledigt, habe es auf eine andere Art lösen können.

Und wie? :)
walter_b Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 135

Windows Vista/XP
Delphi 6
BeitragVerfasst: Do 14.05.09 10:36 
Mit folgender Funktion:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
FUNCTION DimPNG(dateiname: STRING; pos: LONGINT): INTEGER;
VAR f        : FILE OF BYTE;
    d        : INTEGER;
    bytewert : BYTE;
BEGIN
  ASSIGN(f,dateiname);
  RESET(f);
  SEEK(f,pos);
  read(f,bytewert);
  d := bytewert*256;
  read(f,bytewert);
  CLOSE(f);
  DimPNG := d + bytewert;
END;


Und aufgerufen mit diesen zwei Zeilen:

ausblenden Delphi-Quelltext
1:
2:
Writeln(DimPNG(pngfile,18));
writeln(DimPNG(pngfile,22));


gibt es wunderschön die Höhe, Respektive die Breite.