由于网络上Delphi代码很多,学习也很是方便,参考下测试做个截屏程序,尽管只是截取
全屏,但是其实原理雷同,保存起来,以备参考,重点类:TCanvas,screen(全局),
TBitmap==。
procedure TForm1.btn1Click(Sender: TObject);
var
Fullscreen:Tbitmap;
FullscreenCanvas:TCanvas;
dc:HDC;
begin
Fullscreen :=TBitmap .Create ;
Fullscreen .Width :=Screen .Width ;
Fullscreen .Height :=Screen .Height ;
dc:=GetDC(0);
FullscreenCanvas :=TCanvas .Create ;
FullscreenCanvas.Handle:=DC;
Fullscreen.Canvas.CopyRect(Rect(0,0,screen.Width,screen.Height),fullscreenCanvas,Rect(0,0,Screen.Width,Screen.Height));
FullscreenCanvas.Free ;
ReleaseDC(0,dc);
// img1.Picture.Bitmap:=fullscreen; //拷贝下的图象赋给IMAGE对象
if dlgSave1 .Execute then
begin
Fullscreen .SaveToFile (dlgSave1 .FileName );
end;
// img1.Width:=fullscreen.Width;
// img1.Height:=fullscreen.Height;
fullscreen.free; //释放bitmap
Form1 .WindowState :=wsNormal;
end;