Thema: Delphi desktop screenshot

Einzelnen Beitrag anzeigen

a.vollmer
(Gast)

n/a Beiträge
 
#8

Re: desktop screenshot

  Alt 16. Apr 2004, 09:23
Delphi-Quellcode:
procedure TForm1.ScreenToFile(aFileName: string);
var
  Bitmap: TBitmap;
  JPG : TJPEGImage;
  Canvas: TCanvas;
begin
  Canvas := TCanvas.Create;
  try
    Canvas.Handle := GetWindowDC(0);
    Application.ProcessMessages;
    try
      Bitmap := TBitmap.Create;
      Application.ProcessMessages;
      JPG := TJPEGImage.Create;
      Bitmap.PixelFormat:=pf8bit;
       Application.ProcessMessages;
      try
        Bitmap.Width := Screen.DesktopWidth;
        Bitmap.Height:= Screen.DesktopHeight;
        Bitmap.PixelFormat := pfDevice;
         Application.ProcessMessages;
        BitBlt(Bitmap.Canvas.Handle, 0, 0, Pred(Screen.DesktopWidth), Pred(
        Screen.DesktopHeight), Canvas.Handle, Screen.DesktopLeft,
        Screen.DesktopTop, Bitmap.Canvas.CopyMode);
        Application.ProcessMessages;
//Kompression
        JPG.CompressionQuality:=50;
        JPG.Assign(Bitmap);
        Application.ProcessMessages;
        if fileexists(aFileName) then
          deletefile(aFileName);
        JPG.SaveToFile(aFileName);
      finally
//Größe
       resizepictur(aFileName,300,300);
        Bitmap.Free;
        JPG.Free;
      end;
    finally
      ReleaseDC(0, Canvas.Handle);
      Application.ProcessMessages;
    end;
  finally
    Canvas.Free;
  end;
end;

Gruß

Alex
  Mit Zitat antworten Zitat