首先要获得设备环境的句柄,可以通过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屏幕截图的实现的更多相关文章

  1. 用delphi实现完美屏幕截图

    可以截取layered窗口(包括透明窗口)的代码: procedure CaptureScreen(AFileName: string);const  CAPTUREBLT = $40000000;v ...

  2. delphi xe10 获取屏幕截图

    //截取屏幕图片 function MakeScaleScreenshot(Sender: TControl): TBitmap; function GetScreenScale: Single; v ...

  3. Delphi实现屏幕截图、窗口截图、指定区域截图

    Use Jpeg procedure TForm1.snapscreen(a,b,c,d:Integer); var bmpscreen:Tbitmap; jpegscreen:Tjpegimage; ...

  4. Delphi中的RectTracker - 原创

    本文算是副产品,正品是利用FFmpeg从任意视频中生成GIF片段的小程序,写完了就发. 因为要对视频画面进行框选,再生成GIF,所以得有个框选的控件,可Delphi里没有啊,只好自己写一个了. 声明 ...

  5. Delphi和OutputDebugString

    曾经想要实时监控您的Delphi应用程序,并能够查看日志消息吗?当然,您始终可以在RAD Studio IDE中以完全调试模式运行.另一种方法是输出日志消息,例如输出到文本文件.您还可以使用Outpu ...

  6. Delphi 中的 RectTracker - 原创

    本文算是副产品,正品是利用 FFmpeg 从任意视频中生成GIF片段的小程序,写完了就发. V2G 正品已出炉,虽然不大像样,但好歹是能用,请见:用 Delphi 7 实现基于 FFMS2 的视频转 ...

  7. delphi 中OutputDebugString 函数的妙用(使用DebugView或者Pascal Analyzer软件,在运行过程中就能监视和捕捉日志,而且通过网络就能监视)

    原文地址 https://www.peganza.com/delphi-and-outputdebugstring.html 曾经想要实时监控您的Delphi应用程序,并能够查看日志消息吗?当然,您始 ...

  8. 使用Python保存屏幕截图(不使用PIL)

    起因 在极客学院讲授<使用Python编写远程控制程序>的课程中,涉及到查看被控制电脑屏幕截图的功能. 如果使用PIL,这个需求只需要三行代码: from PIL import Image ...

  9. 学习笔记:7z在delphi的应用

    最近做个发邮件的功能,需要将日志文件通过邮件发送回来用于分析,但是日志文件可能会超级大,测算下来一天可能会有800M的大小.所以压缩是不可避免了,delphi中的默认压缩算法整了半天不太好使,就看了看 ...

随机推荐

  1. BBS论坛 登录功能

    四.登录功能 前端页面html代码: <!DOCTYPE html> <html lang="en"> <head> <meta char ...

  2. json条件查询

    完整Demo <html> <head> <script type="text/javascript" src="http://www.w3 ...

  3. 1.Struts2快速入门

    Struts2是一个基于MVC设计模式的Web层框架 Web层框架的特点:前端控制器模式 快速入门 1.下载Struts2的框架包 https://struts.apache.org/ 2.导入jar ...

  4. HTML5布局篇

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title> ...

  5. 秒懂神经网络---BP神经网络具体应用不能说的秘密.

    秒懂神经网络---BP神经网络具体应用不能说的秘密 一.总结 一句话总结: 还是要上课和自己找书找博客学习相结合,这样学习效果才好,不能单视频,也不能单书 BP神经网络就是反向传播神经网络 1.BP神 ...

  6. Spring Boot 遇到空指针

    @Autowired private IRoadRescueService roadRescueService; 千万不要把注入的service类设为static

  7. 使用Windbg调试内核

    Windbg是微软开发的免费源码级调试工具.Windbg可以用于Kernel模式调试和用户模式调试,还可以调试Dump文件. 1.从http://www.microsoft.com/whdc/devt ...

  8. 9、从命令行运行postman脚本及生成测试报告

    本节建议直接看postman官网:https://www.npmjs.com/package/newman 环境准备: 安装nodejs和npm     参考 https://www.runoob.c ...

  9. 剑指offer——33分行从上到下打印二叉树

    题目描述 从上到下按层打印二叉树,同一层结点从左至右输出.每一层输出一行.   题解: 使用BFS,按层打印即可 class Solution { public: vector<vector&l ...

  10. JavaScript网页特效5则

    动态字幕 代码:在需要处加入 < marquee onmouseover=this.stop() onmouseout=this.start()>欢迎访问JavaScript教程网 特点: ...