Einzelnen Beitrag anzeigen

bladecs

Registriert seit: 10. Sep 2005
23 Beiträge
 
Delphi 6 Personal
 
#11

Re: Bild über TSocket senden

  Alt 9. Dez 2005, 19:45
oder so :
Delphi-Quellcode:
procedure ScreenShot(const Bitmap: TBitmap);
var
  DesktopDC: HDC;
begin
  DesktopDC := CreateDC('DISPLAY', nil, nil, nil);
  try
    Bitmap.PixelFormat := pfDevice;
    Bitmap.Width := Screen.Width;
    Bitmap.Height := Screen.Height;
    BitBlt(Bitmap.Canvas.Handle, 0, 0, Screen.Width, Screen.Height, DesktopDC, 0, 0, SRCCOPY);
  finally
    DeleteDC(DesktopDC);
  end;
end;
////////////////////////////////////////////////////////////////////////////


// Für den Client: /////////////////////////////////////////////////////////
var
Rec: Boolean=false;
rM: TMemoryStream;
rSize: Int64;

procedure TForm1.ClientSocket1Read(Sender: TObject;
  Socket: TCustomWinSocket);
var
rL : Integer;
Pic: TJpegimage;
begin
rL := Socket.ReceiveLength;
If rL = 0 then Exit;
If Rec then begin
   Socket.ReceiveBuf(Pointer(Int64(rM.Memory) + rM.Position)^, rL);
   rM.Position := rM.Position + rL;
   ProgressBar1.Position:=round(rm.position/rsize*100); //Fortschritt anzeigen lassen
        If rM.Position = rSize then begin
        ProgressBar1.Position:=100; //Fortschritt anzeigen lassen
        rM.Position := 0;
        Pic := TJpegimage.Create;
            try
            Pic.LoadFromStream(rM);
            Image1.Picture.Assign(Pic);
            Image1.Refresh;
            finally
            Pic.Free;
            end;
        FreeAndNil(rM);
        Rec := False;
        end;
end
else begin
    rSize := StrToInt(Socket.ReceiveText);
    rM := TMemoryStream.Create;
    rM.SetSize(rSize);
    rM.Position := 0;
    Rec := True;
    Socket.SendText('ok');
    end;
end;
// Ende der Clientprocedure ////////////////////////////////////////////////


// Für den Server: /////////////////////////////////////////////////////////
var
sM : TMemoryStream;

procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
  Socket: TCustomWinSocket);
var
Bmp : TBitmap;
Jpeg : TJpegimage;
empfangen:string;
begin
empfangen:=socket.ReceiveText;

if leftstr(empfangen,length('Screenshot'))='Screenshotthen begin
    FreeAndNil(sM);
    Bmp:=TBitmap.Create;
    Jpeg:=TJpegImage.Create;
    sM:=TMemoryStream.Create;
        try
        ScreenShot(bmp);
       Jpeg.CompressionQuality:=strtoint(rightstr(empfangen,length(empfangen)-length('Screenshot')));
        Jpeg.Assign(Bmp);
        Jpeg.SaveToStream(sM);
        finally
        Jpeg.Free;
        Bmp.Free;
        end;
    Socket.SendText(IntToStr(sM.Size));
end;

// Empfänger hat Größe erhalten, das senden der Datei wird durchgeführt
If empfangen='okthen begin
Socket.SendBuf(sM.Memory^, sM.Size);
end;
end;
// Ende der Serverprocedure ///////////////////////////////////////////////////




// Screenshot anfordern
procedure TForm1.Button1Click(Sender: TObject);
begin
if ClientSocket1.Active then begin
ClientSocket1.Socket.SendText('Screenshot'+inttostr(scrollbar1.Position)); //Über die Scrollbar stell ich die Screenshot Qualität ein
end;
end;
  Mit Zitat antworten Zitat