delphi捕捉屏幕

2018-10-30

delphi捕捉屏幕
━━━━━━━━━━━━━━━━━━━━━━━━━━
procedure TForm1.Button1Click(Sender: TObject);
var
h:hdc;
bitmap1:tbitmap;
canvas1:tcanvas;
rect1:trect;
jpeg1:tjpegimage;
begin
bitmap1:=tbitmap.Create;
bitmap1.Width:=screen.Width;
bitmap1.height:=screen.Height;
canvas1:=tcanvas.Create;
h:=getdc(0);
canvas1.Handle:=h;
rect1:=rect(0,0,screen.Width,screen.height);
bitmap1.Canvas.CopyRect(rect1,canvas1,rect1);

jpeg1:=tjpegimage.Create;
jpeg1.Assign(bitmap1);
jpeg1.CompressionQuality:=40;
jpeg1.SaveToFile('c:\eee.jpg'); //保存图片

jpeg1.Free; //jpeg1:tjpegimage;可以把jpeg1定义为全局变量
bitmap1.Free;
canvas1.Free;
releasedc(0,h);
end;

阅读42