Delphi 截屏函数(包含截取鼠标形状)


本文整理自网络,侵删。

 
//--------------------------------------------------------------------------------------------
 function getDateFilename():string;
  var
    s:string;
  begin
    DateTimeToString(s,'yyyymmddhhnnsss',now());
    result:=s;
  end;
//截屏
function captureScreen(x1:integer;y1:integer;x2:integer;y2:integer):tbitmap;
var
  dc:HDC;
  bmp:tbitmap;
  fullCanvas:TCanvas;
begin
  dc:=GetDC(0);
  fullCanvas:=TCanvas.Create;
  fullCanvas.Handle:=dc;
  bmp:=TBitmap.Create;
  try
    bmp.Width:=abs(x2-x1);
    bmp.Height:=abs(y2-y1);
    bmp.Canvas.CopyRect(Rect(0,0,bmp.Width,bmp.Height),fullCanvas,Rect(x1,y1,x2,y2));
    //bmp.SaveToFile('c:\tmp\1.bmp');
  finally
  end;
  result:=bmp;
end;
 
 
//*************** Draw Cursor on the bitmap ******************
Function DrawCursor(Bit : TBitmap) : TBitmap;
Var
Cur : TCursorInfo;
Icn : TIcon;
IcnInfo : TIconInfo;
Rec : TRect;
begin
Icn := TIcon.Create;
Rec := Bit.Canvas.ClipRect;
try
Cur.cbSize := SizeOf(Cur);
if GetCursorInfo(Cur) then
if Cur.flags = CURSOR_SHOWING then
begin
Icn.Handle := CopyIcon(Cur.hCursor);
if GetIconInfo(Icn.Handle, IcnInfo) then
Bit.Canvas.Draw(Cur.ptScreenPos.X - Integer(IcnInfo.XHotSpot) - Rec.Left,
Cur.ptScreenPos.Y - Integer(IcnInfo.YHotSpot) - Rec.Top,
Icn);
end;
finally
Icn.Free;
end;
Result := Bit;
end;
//************ End of cursor drawing *************************

相关阅读 >>

Delphi 几个实用的html解析函数

Delphi 调用外部程序获取程序id,并能关闭该程序

Delphi [函数] unicode 检查字符串是否含中文字

Delphi win32_networkadapter 网卡 参数说明

Delphi cardpanel1 简单的切换

我的Delphi开发经验谈

Delphi 正则表达式tperlregex 类的属性与方法

Delphi xe2读取内存偏移数据代码

Delphi c语言对比指针的用法

Delphi 查看 dll 的输出函数列表

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...