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中的默认压缩算法整了半天不太好使,就看了看 ...
随机推荐
- Java泛型中extends和super的区别?
<? extends T>和<? super T>是Java泛型中的"通配符(Wildcards)"和"边界(Bounds)"的概念. ...
- Spring入门(四)Spring-test模块
自动化转配bean的测试案例分析 package soundsystem; import static org.junit.Assert.*; import org.junit.Rule; impor ...
- 利用ffmpeg进行视频软解播放
前段时间,公司的一个项目需要一个rtsp的播放库,原本打算直接用vlc播放的,但我觉得vlc太庞大了,很多功能没必要,还不如用ffmpeg+d3d简单的实现一个库,因此就有了今天讲的这个东西.一个解码 ...
- SQL Injection简介
- Delphi 字符串函数 StrUtils(大全)
引用单元: StrUtils; 首部 function AnsiResemblesText(const AText, AOther: string): Boolean; $[StrUtils.pas ...
- selenium 无头浏览器headless browser
无头浏览器,即没有界面的浏览器,浏览器该有的功能特性都有. if browser.lower() == "chrome": # 无头浏览器 chrome_opt = webdriv ...
- LUOGU P3723 [AH2017/HNOI2017]礼物 (fft)
传送门 解题思路 首先我们设变化量为\(r\),那么最终的答案就可以写成 : \[ ans=min(\sum\limits_{i=1}^n(a_i-b_i+r)^2) \] \[ ans=min(\s ...
- NX二次开发-UFUN读取表格注释内容UF_TABNOT_ask_cell_text
NX11+VS2013 #include <uf.h> #include <uf_ui.h> #include <uf_tabnot.h> #include < ...
- NX二次开发-UFUN拾取屏幕位置UF_UI_specify_screen_position
#include <uf.h> #include <uf_ui.h> UF_initialize(); //拾取屏幕位置 //在屏幕用鼠标拾取一点 char sMessage[ ...
- NX二次开发-重命名装配组件
在GC工具里面是有一个重命名装配组件的命令的,除了这个外,好像没看到NX里还有其他可以重命名装配组件的命令,本来以为在UFUN ASSEM装配的头文件里会有更改装配部件名字的函数,但是没有找到,可能没 ...