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中的默认压缩算法整了半天不太好使,就看了看 ...
随机推荐
- JS切换
这个效果就跟换肤效果差不多 需要准备两套或两套以上的css <!DOCTYPE html> <html lang="en"> <head> &l ...
- java oop第15章_Socket网络编程
一. TCP/IP协议(Transmission Control Protocol/Internet Protocol)传输控制协议/Internet协议,是通信领域的基础.核心协议, 其他的协议 ...
- TRUNCATE - 清空一个表
SYNOPSIS TRUNCATE [ TABLE ] name DESCRIPTION 描述 TRUNCATE 快速地从一个表中删除所有行.它和无条件的 DELETE 有同样的效果,不过因为它不做表 ...
- 【学术篇】luogu3768 简单的数学题(纯口胡无代码)
真是一道"简单"的数学题呢~ 反演题, 化式子. \[ ans=\sum_{i=1}^n\sum_{j=1}^nijgcd(i,j) \\ =\sum_{i=1}^n\sum_{j ...
- sqlmap结合burpsuite对post请求进行注入测试
1. 浏览器打开目标地址 http://testasp.vulnweb.com/Login.asp 2. 配置burp代理(127.0.0.1:8080)以拦截请求 3. 点击login表单的subm ...
- Delphi ADOQuery的属性 locktype、CursorLocation 、Filter、CursorType、CancelBatch 和 UpdateBatch
以下数据,部分来自网络的收集,部分为自己测试后的原创整理,希望对你有帮助,更新会注明日期. 1.locktype 指定用户打开数据集时对数据集的锁定级别: ltUnspecified 未指定锁定 ...
- HTML5布局篇
<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title> ...
- delphi里为程序任务栏右键菜单添加自定义菜单
本文讲解的是为自身程序的任务栏右键菜单里添加自己定义的菜单的方法: delphi添加任务栏右键菜单 procedure TForm1.FormCreate(Sender: TObject); var ...
- NX二次开发-C++time函数计时
NX11+VS2013 #include <uf.h> #include <uf_modl.h> #include <uf_ui.h> #include <t ...
- HDU5669
目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:传送门 Portal 原题目描述在最下面. 给你n个点 ...