Autor Beitrag
gardener
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Do 03.05.07 11:11 
Hallo allen,

ich habe ein Problem. Ich bekommen ein custom bitmap datie via TCP/Ip und muss dies so konvertieren das ich der Header ersetzt durch ein standard Header.

Jetzt mache ich das so:

-Hole das Datei rein und speicher das auf den festplatte
-mache ein leere Bitmap mit die richtig Header Daten
-Kopiere dann die Pixel Daten vom gespeicherte Datei
-Speichere diese Datei auch auf dem festplatte

Jetzt kann ich die Bitmap im meinem program benutzen

Es functioniert prima, aber meinem rechner kann dann nur das :(
weil der CPU immer gegen die 100% belastet wird.

Wie kann ich das schneller machen? Ich vermuttte mit stream und oder scanline aber ich bin anfanger und verstehe das noch nicht alles

Danke!!

Tom

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:
  If client1.socket.connected then
  begin
    try
          // define path and file ext
        PicturePath := ExtractFileDir(ParamStr(0)) +
                           '\' + Client1.Host + '_Screen.bmp';
        if FileExists (PicturePath) then DeleteFile(PicturePath);
        Stream := TFileStream.Create(PicturePath,fmCreate);
        Size := Client1.Socket.ReadInteger;
        idStream := TiDStreamVCL.Create(Stream,false);
        //Read from socketbuffer
        Client1.Socket.ReadStream(idStream,Size,False);
        FreeAndNil(Stream);

          // define BMP header
          With MyBitmapHeader do
          Begin
              bfType1         :=  $42;
              bfType2         :=  $4D;
              bfSize          :=  $00000000;
              bfReserved1     :=  $0000;
              bfReserved2     :=  $0000;
              bfOffBits       :=  $36;
              biSize          :=  $28;
              biWidth         :=  640;//$00000280;
              biHeight        :=  480;//$000001e0;
              biPlanes        :=  1;
              biBitCount      :=  8;
              biCompression   :=  $00000000;
              biSizeImage     :=  $00000000;
              biXPelsPerMeter :=  $00000000;
              biYPelsPerMeter :=  $00000000;
              biClrUsed       :=  180;//$00000000;
              biClrImportant  :=  180;//$00000000;
              //Palette := CreatePalette(PLogPalette(@MaxLogPalette)^);
          end;

          //Open output file
          if FileExists (dImage) then DeleteFile (dImage);
          AssignFile(MyFile, dImage);
          Rewrite(MyFile,1);

          //Write the header
          BlockWrite (MyFile, MyBitmapHeader, SizeOf(TBmpHeader));
          //Open the source file
          assignfile(srcfile,PicturePath);
          Reset(srcfile,1);

          // fill the destination file with the pixel data from the source
          for i:= 1 to 640 do
          begin
                for j:= 1 to 480 do
                begin
                    if not EOF(SrcFile) then begin
                      BlockRead(Srcfile,SrcBuff,1); //read 1 byte from source (1 block)
                      BlockWrite(MyFile, SrcBuff,1); //write 1 byte to destination
                    end;
                end;
          end;
          // closes both files
          CloseFile(srcFile);
          CloseFile(MyFile);
          // call image procedure
          RefreshImage(Client.Host, dImage);
          finally
            Stream.Free;
          end;


Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt
Moderiert von user profile iconChristian S.: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Do 03.05.2007 um 16:40
Dezipaitor
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 220



BeitragVerfasst: Do 03.05.07 15:27 
nimm doch TMemoryStream statt TFileStream
Lossy eX
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1048
Erhaltene Danke: 4



BeitragVerfasst: Do 03.05.07 17:23 
Ist das beides nicht ein bisschen für die Füße? Warum packst du deine Daten nicht gleich in ein TBitmap? Mit Scanline kannst du die Daten direkt ins TBitmap kopieren ohne Umwege über irgendwas.

_________________
Nur die Menschheit ist arrogant genug, um zu glauben sie sei die einzige intelligente Lebensform im All. Wo nicht mal das nachhaltig bewiesen wurde.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8553
Erhaltene Danke: 479

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 03.05.07 17:28 
Das Problem ist, dass du jedes Byte einzeln rüberschaufelst. Wesentlich schneller geht es, wenn du mehr auf einmal kopierst. Einen Stapel Papier trägt man ja auch nicht von A nach B, indem man jedes Blatt einzeln anpackt ;-)

_________________
We are, we were and will not be.