Einzelnen Beitrag anzeigen

LAWn-M0W3R

Registriert seit: 31. Jul 2006
Ort: Potsdam / Berlin
38 Beiträge
 
#3

Re: Problem: TMemoryStream und JPEG Metzwerküberwachungssoft

  Alt 13. Sep 2006, 09:17
OK, ich verkürze das ganze einfach mal:
Ich bin leider auch in der letzten Zeit nicht mehr dazu gekommen meinen Code nochmal genauer zu untersuchen, aber ich bin es auch leid!
Zitat:
FreeAndNil(Stream);
JPG.SaveToStream(Stream);
Das steht schon so drin.

Server:
Delphi-Quellcode:
var
  Form1: TForm;
  voice: Variant;
  Stream : TMemoryStream;

implementation
...

//Screenshot und laden des Screenshots in den Stream:
procedure TForm1.Screenshot;
var
   W, H: Integer;
   DesktopDC: HDC;
   BMP: TBitmap;
   JPG: TJpegImage;
begin
DesktopDC := CreateDC('Display', nil,nil,nil);
W := Screen.Width;
H := Screen.Height;
BMP := TBitmap.Create;
JPG := TJpegImage.Create;
try
   BMP.HandleType := bmDDB;
   BMP.PixelFormat := pf24Bit;
   BMP.Width := W;
   BMP.Height := H;
   BitBlt(BMP.Canvas.Handle, 0, 0, Screen.Width, Screen.Height, DesktopDC, 0, 0, SRCCOPY);
   JPG.CompressionQuality := 80;
   JPG.Assign(BMP);
   FreeAndNil(Stream);
   JPG.SaveToStream(Stream);
   finally
   BMP.Free;
   Jpg.Free;
   DeleteDC(DesktopDC);
   end;
end;
////////////////////////////////////////////////////////////////////////////////


procedure TForm1.ServerClientRead(Sender: TObject;
  Socket: TCustomWinSocket);
begin
Log.Lines.Add(Socket.ReceiveText);

If leftstr(Log.Lines[Log.Lines.Capacity-1],length('SCREENSHOT'))='SCREENSHOT'
then
begin
  Screenshot;


//!!!!!!!!!!!!!!!!!!!!AccessViolation Error
  Server.Socket.SendText(IntToStr(Stream.Size));

end;
If leftstr(Log.Lines[Log.Lines.Capacity -1],length('OK'))='OK
then Server.Socket.SendBuf(Stream.Memory^, Stream.Size);
end;
Client:
Delphi-Quellcode:
procedure TNetview.TimerTimer(Sender: TObject);
var
  rL : Integer;
  Pic: TJpegimage;
begin
SendText(Ehost, 'SCREENSHOT');
rL := ClientSocket.Socket.ReceiveLength;
If rL = 0 then Exit;
If Rec
then
   begin
   ClientSocket.Socket.ReceiveBuf(Pointer(Int64(Stream.Memory) + Stream.Position)^, rL);
   Stream.Position := Stream.Position + rL;
// ProgressBar1.Position:=round(Stream.position/rsize*100); //Fortschritt anzeigen lassen
        If Stream.Position = rSize then begin
// ProgressBar1.Position:=100; //Fortschritt anzeigen lassen
        Stream.Position := 0;
        Pic := TJpegimage.Create;
            try
            Pic.LoadFromStream(Stream);
            remote.Iscreen.Picture.Assign(Pic);
            remote.Iscreen.Refresh;
            finally
            Pic.Free;
            end;
        ClientSocket.Socket.SendText('OK');
        FreeAndNil(Stream);
        Rec := False;
        end;
    end
else
    begin
    rSize := StrToInt(ClientSocket.Socket.ReceiveText);
    Stream := TMemoryStream.Create;
    Stream.SetSize(rSize);
    Stream.Position := 0;
    Rec := True;
    end;
end;
Errors: AccessViolation, Adressfehler



Bitte Hilfe! Bitte antworten!
  Mit Zitat antworten Zitat