Hallo,
mein kleines Programm beinhaltet ein Formular, dass die Eigenschaft TransparentColor den Zustand Wahr hat. Nun möchte ich ein Schnappschuß des eben genannten machen.
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;
procedure TForm1.Button1Click(Sender: TObject);
begin
ScreenToFile('Screen1.jpg');
end;
Lichtet mir nur den Desktop ab. Das Form leider nicht.