Delphi屏幕截图的实现
首先要获得设备环境的句柄,可以通过GetDC函数来获得,对于这个函数,MSDN上是这样说明的
The GetDC function retrieves a handle to a device context (DC) for the client area of a specified window or for the entire screen. You can use the returned handle in subsequent GDI functions to draw in the DC. The device context is an opaque data structure, whose values are used internally by GDI.
The GetDCEx function is an extension to GetDC, which gives an application more control over how and whether clipping occurs in the client area.
Syntax
HDC GetDC(
__in HWND hWnd
);
Parameters
hWnd [in]
A handle to the window whose DC is to be retrieved. If this value is NULL, GetDC retrieves the DC for the entire screen.
Return value
If the function succeeds, the return value is a handle to the DC for the specified window's client area.
If the function fails, the return value is NULL.
1.申明一全变量存储GetDC方法得到的句柄,HDC类型
?
1
2
var
dc:HDC;
2.在适当时候调用GetDC,將得到的句柄赋值给变量dc,并將得到的句柄赋值给Canvas的句柄(fullCanvas是变量)
1 dc:=GetDC(0);
2 fullCanvas:=TCanvas.Create;
3 fullCanvas.Handle:=dc;
3.然后就是对fullCanvas进行操作,这里也要用到CopyRect函数
procedure CopyRect(const Dest: TRect; Canvas: TCanvas; const Source: TRect);
Copies part of an image from another canvas into the canvas.Use CopyRect to transfer part of the image on another canvas to the image of the TCanvas object.
Dest specifies the rectangle on the canvas where the source image will be copied. The Canvas parameter specifies the canvas with the source image.
Source specifies a rectangle bounding the portion of the source canvas that will be copied.The portion of the source canvas is copied using the mode specified by CopyMode.
一句话就是,将Canvas中的Source大小的区域拷贝到目标canvas中的Dest區域中,如果这二个面积不相等,会有缩放效果,如果不想有此效果,这二个区域的长宽相等
复制代码
1 if SavePictureDialog1.Execute then
2 begin
3 bm:=TBitmap.Create;
4 try
5 bm.Width:=abs(x2-x1);
6 bm.Height:=abs(y2-y1);
7 bm.Canvas.CopyRect(Rect(0,0,bm.Width,bm.Height),fullCanvas,Rect(x1,y1,x2,y2));
8 bm.SaveToFile(SavePictureDialog1.FileName+'.bmp');
9 finally
10 bm.Free;
11 end;
复制代码
其中bm.width:=ABS(x2-x1),bm.heigth:=ABS(y2-y1),如果要全屏截图,则将二个RECT都设置为Rect(0,0,Screen.Width,Screen.heigth)
程序运行如下
要实现有背景的黑层行是这样操作的
(1).设置窗体 AlphaBlend为True,AlphaBlendVaue为150,BorderStyle:=bsNone;
(2).在窗体创建时写如下语句
1 SetWindowPos(0,HWND_TOP,0,0,Screen.Width,Screen.Height,SWP_DRAWFRAME);
2 ClientHeight:=Screen.Height;
3 ClientWidth:=Screen.Width;
Delphi屏幕截图的实现的更多相关文章
- 用delphi实现完美屏幕截图
可以截取layered窗口(包括透明窗口)的代码: procedure CaptureScreen(AFileName: string);const CAPTUREBLT = $40000000;v ...
- delphi xe10 获取屏幕截图
//截取屏幕图片 function MakeScaleScreenshot(Sender: TControl): TBitmap; function GetScreenScale: Single; v ...
- Delphi实现屏幕截图、窗口截图、指定区域截图
Use Jpeg procedure TForm1.snapscreen(a,b,c,d:Integer); var bmpscreen:Tbitmap; jpegscreen:Tjpegimage; ...
- Delphi中的RectTracker - 原创
本文算是副产品,正品是利用FFmpeg从任意视频中生成GIF片段的小程序,写完了就发. 因为要对视频画面进行框选,再生成GIF,所以得有个框选的控件,可Delphi里没有啊,只好自己写一个了. 声明 ...
- Delphi和OutputDebugString
曾经想要实时监控您的Delphi应用程序,并能够查看日志消息吗?当然,您始终可以在RAD Studio IDE中以完全调试模式运行.另一种方法是输出日志消息,例如输出到文本文件.您还可以使用Outpu ...
- Delphi 中的 RectTracker - 原创
本文算是副产品,正品是利用 FFmpeg 从任意视频中生成GIF片段的小程序,写完了就发. V2G 正品已出炉,虽然不大像样,但好歹是能用,请见:用 Delphi 7 实现基于 FFMS2 的视频转 ...
- delphi 中OutputDebugString 函数的妙用(使用DebugView或者Pascal Analyzer软件,在运行过程中就能监视和捕捉日志,而且通过网络就能监视)
原文地址 https://www.peganza.com/delphi-and-outputdebugstring.html 曾经想要实时监控您的Delphi应用程序,并能够查看日志消息吗?当然,您始 ...
- 使用Python保存屏幕截图(不使用PIL)
起因 在极客学院讲授<使用Python编写远程控制程序>的课程中,涉及到查看被控制电脑屏幕截图的功能. 如果使用PIL,这个需求只需要三行代码: from PIL import Image ...
- 学习笔记:7z在delphi的应用
最近做个发邮件的功能,需要将日志文件通过邮件发送回来用于分析,但是日志文件可能会超级大,测算下来一天可能会有800M的大小.所以压缩是不可避免了,delphi中的默认压缩算法整了半天不太好使,就看了看 ...
随机推荐
- 基于OpenResty与Consul实现服务网格ServiceMesh
一.逻辑架构 1.基于OpenResty开发智能代理: 利用其动态可编程特性,动态化配置nginx服务路由: 2.需要向OpenResty添加weibo开源的upsync服务发现模块: 3.基于con ...
- jq容易混淆点
jQuery链式编程: 原:把当前元素颜色修改为红色,其余兄弟颜色不变 $(this).css("color",'red') ; $(this).siblings().css(&q ...
- [转] js对键盘输入事件绑定到特定按钮。
<script type="text/javascript" language="javascript"> document.onkeyup = f ...
- Samza基本概念
- Android SDK中无法安装HAXM installer
一.原因: 刚搭建好环境,当我想打开Android Studio 自带的模拟器时,出现如下: /dev/kvm is not found 二.解决步骤: 1.点击File -- Setti ...
- 组合,模板,bolck块
如果前面和后面的变量名相同,则后面的变量名会覆盖前面的变量名 模板可以多次使用,只需要将is指定template的name,就可以重复使用该模板,只需要将不同的item值赋值给data就可以实现. 可 ...
- API Gateway和Route 53及CloudFront的连携使用
API Gateway部署出来之后的url网址对于普通用户并不友好,所以肯定是需要一个正常的域名来作为url进行访问. 主要有以下几点, API Gateway可以自定义域名 自定义的域名要从Rout ...
- DLL注入技术之依赖可信进程注入
DLL注入技术之依赖可信进程注入 依赖可信进程注入原理是利用Windows 系统中Services.exe这个权限较高的进程,首先将a.dll远线程注入到Services.exe中,再利用a.dll将 ...
- CSS:CSS 总结
ylbtech-CSS:CSS 总结 1.返回顶部 1. 你已经学习了CSS,下一步学习什么呢? CSS 总结 本教程已向你讲解了如何创建样式表来同时控制多重页面的样式和布局. 你已经学会如何使用 C ...
- OSI七层网络模型分别是哪七层?各运行那些协议?
本文摘自:https://blog.csdn.net/JeremyZJM/article/details/78184775 应用层 DHCP · DNS · FTP · Gopher · HTTP · ...