Autor Beitrag
maaalin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 41



BeitragVerfasst: Mo 02.01.06 15:17 
hi, also ich wollte nun ein programm schreiben, das mir alle pngs aus einer datei herausschreibt.

die datei habe ich per
ausblenden Delphi-Quelltext
1:
Fstream:=TFileStream.Create(Opendialog1.FileName, fmOpenRead);					

in einen stream geladen. doch nun muss ich das ganze ja irgendwie von
89 50 4E 47 (also dem anfang einer png datei)
bis
49 45 4E 44 AE 42 60 82 (das ende einer png datei)
kopieren lassen.

wie gehe ich am besten dabei vor, ich weiss ja nicht, wie gross der teil dazwischen ist. danach würde ich das ganze als png datei halt speichern lassen.

mfg

maaalin
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Mo 02.01.06 15:42 
Wenn du den Stream durchgehst und dir die Anfangs- und die Endposition merkst, sollte das doch eigentlich kein Problem sein, oder?

AXMD
maaalin Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 41



BeitragVerfasst: Mo 02.01.06 15:46 
ja ich hab gerade noch etwas rumgesucht und ich glaube was ich brauche ist
copy und pos, oder soetwas in der art
maaalin Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 41



BeitragVerfasst: Di 03.01.06 12:43 
hmm, funktioniert copy und pos überhaupt mit nem filestream?
ich komm ehrlichgesagt nicht wirklich weiter
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Di 03.01.06 12:46 
Nein, Copy und Pos ist für Strings und dynamische Arrays - sofern wir die gleichen Funktionen meinen. Schau mal in der Delphihilfe unter TFileStream - da gibt's haufenweise Methoden, die dir nützlich sein könnten.

AXMD
maaalin Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 41



BeitragVerfasst: Di 03.01.06 12:55 
ok, also muss ich in dem stream erst nach dem anfang von einem bild suchen und diesen mit position festlegen,
dann schauen wieviele byte zwischen dem anfang und dem ende geschrieben sind.

jex könnte ich das ganze mit copyFrom in einen anderen stream kopieren und diesen abspeichern oder?
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Di 03.01.06 12:56 
Ja, zum Beispiel. So war's gedacht.

AXMD
maaalin Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 41



BeitragVerfasst: Di 03.01.06 12:58 
ok danke, dann werd ich mal ein bischen im forum rumsuchen :)
wird jetzt schon irgendwie klappen
maaalin Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 41



BeitragVerfasst: Di 03.01.06 14:01 
so ich habe folgende prozedur hier im forum gefunden ( und etwas verändert ):

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.SearchStreamForContent(Stream:TStream; SeekedContent:String; liste : TListBox);
var ChrFound:Char;
var Line:String;
begin
  While (Stream.Position<Stream.Size) do
  begin
    Line:='';
    Repeat
      Stream.ReadBuffer(ChrFound,SizeOf(ChrFound));
      Line:=Line+ChrFound;
    until (Stream.Position=Stream.Size) or (ChrFound=#10);
    if Pos(SeekedContent,Line)>0 then
   Liste.Items.Add(IntToStr(Stream.Position))
  end;
end;

jetzt such ich einmal nach dem anfang des bildes und einmal nach dem ende des bildes.
dann hab ich alle start/endvariablen untereinander in 2 listboxen.

aber das problem ist, wenn ich die beiden suchprozeduren starten möchte, führt das programm
nur eine davon aus und zwar die, die ich zuerst starte.
wie kann ich dem programm sagen, dass es warten soll?
Horst_H
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1654
Erhaltene Danke: 244

WIN10,PuppyLinux
FreePascal,Lazarus
BeitragVerfasst: Di 03.01.06 18:33 
Hallo,

du musst einfach nur zwei Listen erstellen und kombinieren.
Du hast aber ein problem, dass du die Daten in einen String einliest der zufallsmaessig, die komplette Datei werden kann.
Ich habe mal ein Programm fuer Turbo Pascal geschrieben, um nach einer Zeichenkette(maximal 255 Zeichen lang) zu suchen.Nur die Anzahl und die momentane Position->musst Du in einer Liste speichern werden ausgegeben.

ausblenden volle Höhe Delphi-Quelltext
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:
program Suchtext;

{$AppTYPE CONSOLE}
uses
  sysutils;
const
   num=100;
   Fname = 'C:\Such.txt';
   Gname = 'C:\Test.txt';
   BufSize = 4096;
   Textlaenge = 255;
type
   tBuffer         = array[0..BufSize-1] of char;
   tBufferKomplett = array[-Textlaenge..BufSize-1] of char;
   tSuchfile = file;
var
   T1,T0 :TDateTime;
   i,k,
   Anzahl,
   leng      : integer;
   MaxPos,
   Pos_Alt,
   Position,
   DateiPosition  : integer;
   Gelesen   : integer;

   stri      : string;
   Buffer    : tBufferkomplett;

   Bufp      : pchar;
   g : tSuchfile;
   f : text;
   ErstesZeichen : char;
   found     : boolean;


{variablen}
BEGIN
{strings in datei}
{Erzeuge TextText}
assign(f,GName);
if Not(FileExists(Gname)) then
  begin
  rewrite(F);
  for i := 0 to 1999999 do
    write(F,Format('%d ',[i]));
  close (F);
  end;
{Erzeuge SuchText}
assign(f,FName);

rewrite(f);
writeln(f,'111');
writeln(f,'010101');
writeln(f,'99999');
writeln(f,'TAG');
close(f);

reset(f);

assign(g,GName);

for k:=1 to num do {jeder string}
begin
   If NOT(EOF(F)) then
   begin
      readln(f,stri);
      leng := length(stri);
      ErstesZeichen := Stri[1];
      writeln('Suche nach: ',Stri);
      {Daten wieder an die Startposition}
      Bufp := @Buffer[0];
      reset(g,1);
      DateiPosition := 1;
      Anzahl := 0;
      T0 := time;
      Pos_Alt := 0;
      repeat
        BlockRead(g,Buffer[0],BufSize,Gelesen);
        Position := Pos_Alt;
        MaxPos := Gelesen-leng;
        while Position <= MaxPos do
          begin
          while Position <= MaxPos do
            begin
            If Bufp[Position] = ErstesZeichen then
              break;
            Inc(Position);
            end;
            i := 0;
            repeat
              inc(i);
              found := (Bufp[Position] = Stri[i]);
              inc(Position);
            until not(found) or (i = leng);
            Position := Position-i+1;
            if found then
              begin
              write(DateiPosition+Position);
              write(#8#8#8#8#8#8#8#8#8#8#8);
              inc(Anzahl);
              end;
         end;
         inc(DateiPosition,Gelesen);
         Pos_Alt := Position-Gelesen;
         if Pos_Alt <>0 then
            move(Buffer[BufSize-Leng+1],Buffer[-Leng+1],Leng-1);
      until gelesen <> BufSize;
      writeln;
      T1 := time;
      Writeln(Anzahl,' "',stri,'" in ');
      writeln((T1-T0)*86400:0:2,' s gefunden!');
      writeln;
   end;
end;
writeln('-------ENDE-------');
readln

end.


Gruss Horst
Neidhard von Reuental
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 268

XP
BDS 2006 Prof
BeitragVerfasst: Di 03.01.06 20:04 
und wie gehts voran? :)
maaalin Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 41



BeitragVerfasst: Di 03.01.06 21:11 
jap thx erstmal allen. es läuft jetzt so wie ich es wollte.
und ja ich habs mit 2 listen gemacht.

hab halt 2 listboxen, in denen die verschiedenen offsets gespeichert werden, jeweils anfang und ende.
und nunja, jetzt kann ich das ganze ja leicht in einen neuen stream kopieren