unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, JPEG, ExtCtrls, ExtDlgs;
type
TForm1 =
class(TForm)
Button1: TButton;
Image1: TImage;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
ScreenStream: TMemoryStream;
implementation
{$R *.dfm}
procedure Screenshot(Quality: Integer);
type
TJPEGQualityRange = 1..100;
var
DeskWnd: HWnd;
DeskDC: HDC;
DeskCv: TCanvas;
R: TRect;
W, H: Integer;
Jpg: TJpegImage;
BMP: TBitmap;
begin
DeskWnd := GetDesktopWindow;
DeskDC := GetWindowDC(DeskWnd);
DeskCv := TCanvas.Create;
DeskCv.Handle := DeskDC;
W := Screen.Width;
H := Screen.Height;
R := Bounds(0, 0, W, H);
BMP := TBitmap.Create;
Jpg := TJpegImage.Create;
try
BMP.HandleType := bmDIB;
BMP.PixelFormat := pf24Bit;
BMP.Width := W;
BMP.Height := H;
BMP.Canvas.CopyMode := cmSrcCopy;
BMP.Canvas.CopyRect(R, DeskCv, R);
Jpg.CompressionQuality := Quality;
Jpg.Assign(BMP);
Jpg.SaveToStream(ScreenStream);
finally
BMP.Free;
Jpg.Free;
DeskCv.Free;
ReleaseDC(DeskWnd, DeskDC);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ScreenStream:=TMemoryStream.Create;
Screenshot(80);
try
Image1.Picture.Bitmap.LoadFromStream(ScreenStream);
except
ScreenStream.Free;
end;
end;