屏幕抓取delphi


本文整理自网络,侵删。

 procedure CopyCurrentDesktop(IncludeCur:Boolean);
var
DesktophWnd:hWnd;
DesktopDC:hWnd;
CursorhWnd:hWnd;
CurPos:Tpoint;
Rect:TRect;
Bitmap:TBitmap;
begin
DesktophWnd := GetDesktopWindow();
DesktopDC := GetDC(DesktophWnd);
GetWindowRect(DesktophWnd, Rect);
if IncludeCur then
begin
CursorhWnd:=GetCursor(); //捕获当前鼠标指针句柄
GetCursorPos(CurPos);
end; //获取当前鼠标指针的位置坐标
Bitmap := TBitmap.Create;//生成一个Tbitmap类型的实例对象
Bitmap.Width := Rect.Right-Rect.Left;
Bitmap.Height := Rect.Bottom-Rect.Top;
BitBlt(Bitmap.Canvas.Handle, 0, 0,
Bitmap.Width, Bitmap.Height, DesktopDC, 0, 0, SRCCOPY);

//在抓取到的位图对象上绘制鼠标
if IncludeCur then
DrawIcon(Bitmap.Canvas.Handle, CurPos.X, CurPos.Y, CursorhWnd);
ReleaseDC(DesktophWnd, DesktopDC);
Bitmap.SaveToFile('C:\Desktop.bmp'); //使用类方法SaveToFile保存文件
Bitmap.Free;
ShowMessage('成功抓取屏幕并保存图像至C:\Desktop.bmp文件!');
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
Button2.Enabled:=False;
if RadioButton1.Checked then
CopyCurrentDesktop(True)
else
CopyCurrentDesktop(False);
Button2.Enabled:=True;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
ShellExecute(handle,'open','C:\Desktop.bmp',nil,nil,SW_Normal);
end;

end.

相关阅读 >>

Delphi动态设置spcomm的属性值

Delphi获取进程占用内存

Delphi xe(indy10)tidbytes转ansistring的实现

Delphi android 保持唤醒状态

Delphi 用正则表达式检查一个串是否是电信的手机号

Delphi 拖动form上的图片,form一起动

Delphi dll 字符串传递例子

Delphi thread.queue与synchronize的区别

Delphi获取access中的表名代码

Delphi 解析json生成json

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



打赏

取消

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

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

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

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

评论

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