uses WinTypes, WinProcs, Forms, Controls, Classes, Graphics;
function CaptureScreenRect( ARect: TRect ): TBitmap;
var
ScreenDC: HDC;
begin
Result := TBitmap.Create;
with Result, ARect do
begin
Width := Right - Left;
Height := Bottom - Top;
ScreenDC := GetDC( 0 );
try
BitBlt( Canvas.Handle, 0, 0, Width, Height, ScreenDC,
Left, Top, SRCCOPY );
finally
ReleaseDC( 0, ScreenDC );
end;
end;
end;
思路是这样的
parameter 是一个 TRect, 也就是一个 4 方形,你可以设定,是这样的
TRect defines a rectangle.
Unit
Types
Delphi syntax:
type
TRect = packed record
case Integer of
0: (Left, Top, Right, Bottom: Integer);
1: (TopLeft, BottomRight: TPoint);
end;
返回一个 Bitmap 也就是图像拉
创建一个新的 bitmap instance
HDC 是一个 device context (DC),也就可以利用 BitBlt 把windows 图像转到 bitmap 里了。
完整代码在这里,朋友可以直接调用
unit ScrnCap;
interface
uses WinTypes, WinProcs, Forms, Controls, Classes, Graphics;
function CaptureScreenRect( ARect: TRect ): TBitmap;
function CaptureScreen: TBitmap;
function CaptureClientImage( Control: TControl ): TBitmap;
function CaptureControlImage( Control: TControl ): TBitmap;
function CaptureWindowImage( Wnd: HWND ): TBitmap;
implementation
{==============================================================================}
{ Use this to capture a rectangle on the screen... }
function CaptureScreenRect( ARect: TRect ): TBitmap;
{==============================================================================}
var
ScreenDC: HDC;
begin
Result := TBitmap.Create;
with Result, ARect do
begin
Width := Right - Left;
Height := Bottom - Top;
ScreenDC := GetDC( 0 );
try
BitBlt( Canvas.Handle, 0, 0, Width, Height, ScreenDC,
Left, Top, SRCCOPY );
finally
ReleaseDC( 0, ScreenDC );
end;
end;
end;
{==============================================================================}
{ Use this to capture the entire screen... }
function CaptureScreen: TBitmap;
{==============================================================================}
begin
with Screen do
Result := CaptureScreenRect( Rect( 0, 0, Width, Height ));
end;
{==============================================================================}
{ Use this to capture just the client area of a form or control... }
function CaptureClientImage( Control: TControl ): TBitmap;
{==============================================================================}
begin
with Control, Control.ClientOrigin do
Result := CaptureScreenRect( Bounds( X, Y, ClientWidth,
ClientHeight ));
end;
{==============================================================================}
{ Use this to capture an entire form or control... }
function CaptureControlImage( Control: TControl ): TBitmap;
{==============================================================================}
begin
with Control do
if Parent = nil then
Result := CaptureScreenRect( Bounds( Left, Top, Width,
Height ))
else
with Parent.ClientToScreen( Point( Left, Top )) do
Result := CaptureScreenRect( Bounds( X, Y, Width,
Height ));
end;
{==============================================================================}
{ Use this to capture an entire form or control paased as an API hWnd... }
function CaptureWindowImage( Wnd: HWND ): TBitmap;
{==============================================================================}
var
R: TRect;
begin
GetWindowRect(Wnd, R);
Result := CaptureScreenRect(R);
end;
end.

Delphi中BitBlt函数实现屏幕对象抓图的更多相关文章

  1. Delphi中的函数指针判断是否为空

    delphi函数指针 只有@@p才代表了函数指针本身的地址   assigned(p) 判断是否为空 或者用 @p=nil 来判断函数指针是不是为空 Delphi中的函数指针实际上就是指针,只是在使用 ...

  2. Delphi中 StrToIntDef函数的用法

    Delphi中 StrToIntDef函数的用法:比如我要判断一个文本框里输入的字符串能不能转换为integer类型,如果能,则返回转换后的整型数据,如果不能,则返回整数0,那么我就可以用strtoi ...

  3. Delphi中的Sender:TObject对象解析

    Delphi中的Sender:TObject对象解析 procedure TForm1.Button1Click(Sender: TObject); begin end; 解析:Procedure是过 ...

  4. Delphi中的Sender:TObject对象解析转载

    https://blog.csdn.net/jl_tiny/article/details/24376661 Delphi中的Sender:TObject对象解析 procedure TForm1.B ...

  5. delphi中move函数的正确理解(const和var一样,都是传地址,所以Move是传地址,而恰恰不是传值)太精彩了 good

    我们能看到以下代码var pSource,pDest:PChar;     len: integer;.......................//一些代码Move(pSource,pDest,l ...

  6. Javascript中的函数(Function)与对象(Object)的关系

    今天我们来尝试理解Function和Object.因为这个里面有些人前期可能会搞糊涂.他们之间到底是什么关系.当然也不除外当初的我. 注意:官方定义: 在Javascript中,每一个函数实际上都是一 ...

  7. js中的函数,Date对象,Math对象和数组对象

    函数就是完成某个功能的一组语句,js中的函数由关键字 function + 函数名 + 一组参数定义;函数在定义后可以被重复调用,通常将常用的功能写成一个函数,利用函数可以使代码的组织结构更多清晰. ...

  8. JavaScript中Function函数与Object对象的关系

    函数对象和其他内部对象的关系 除了函数对象,还有很多内部对象,比如:Object.Array.Date.RegExp.Math.Error.这些名称实际上表示一个 类型,可以通过new操作符返回一个对 ...

  9. Javascript中的"函数是第一类对象(first-class object)"

    本身这句话很好解释,函数有两个主要特点,援引自 陈新 译的<JavaScript模式>: 1.函数是第一类对象: 函数可以在运行时动态创建,还可以在程序执行过程中创建. 函数可以分配变量, ...

随机推荐

  1. 《c程序设计语言》读书笔记--字符串比较

    举例如下: char a[10]; 1.定义的时候直接用字符串赋值 char a[10]="hello"; 注意:不能先定义再给它赋值,如  char a[10];  a[10]= ...

  2. asp开发微信扫码支付

    这个任务已经给了.现在正在学习开发中.主要注意的是2点. 1:返回参数的验证. 2:通知后业务处理和处理后返回财付通.大部分操作,api中已经处理好. 现在需要的业务逻辑部分. 需要正确3个参数  r ...

  3. Python 数据类型转换

    Python提供的基本数据类型主要有:布尔类型.整型.浮点型.字符串.列表.元组.集合.字典.日期等等 函数                      描述     type(x)  x的数据类型   ...

  4. shell 块注释

    方法一 : ' 被注释的多行内容 ' 方法二 :<<eof 被注释的多行内容 eof 方法三 :<<! 被注释的多行内容 ! 方法四 if false ; then 被注释的多 ...

  5. 编程时 对 用途这个字段定义时 不要用using 这个英文

    编程时  对 用途这个字段定义时  不要用using 这个英文

  6. android SDK 更新

    在SDK Manager下Tools->Options打开了SDK Manager的Settings,选中“Force https://… sources to be fetched using ...

  7. php多种实例理解无限极分类

  8. 【英语】Bingo口语笔记(73) - 以tly,tely结尾的误读

  9. Maven加依赖包

    对于初学maven的人来说刚开始会有个困惑,那就是怎么知道依赖的jar的groupId和atrifactId是什么, 比如要依赖mybatis,会在pom.xml中配置如下: <dependen ...

  10. 部署HBase远程访问的问题集合(Eclipse)

    实现远程访问HBase,可以通过Eclipse开发工具方便进行代码调试. 为了方便jar包各种版本的管理,才用maven进行代码构建 首先,下载并安装maven以及M2Eclipse插件 其次,配置m ...