您现在的位置:首页 >> 图形媒体 >> 图形媒体 >> 内容

Delphi中使用DirectX截屏函数(4)

时间:2011/9/3 15:01:39 点击:

再给一个直接使用系统GDI实现的抓屏

procedure CaptureScreen(const FileName: string);overload;
var
  nScreenWidth,nScreenHeight: integer;
  ScreenDc,hCaptureDC: HDC;
  bmp: TBitmap;
begin
  nScreenWidth := GetSystemMetrics(SM_CXSCREEN);
  nScreenHeight := GetSystemMetrics(SM_CYSCREEN);
  ScreenDc := GetDC(GetDesktopWindow);
  hCaptureDC := CreateCompatibleDC(ScreenDc);
  bmp := TBitmap.Create;
  bmp.Handle :=CreateCompatibleBitmap(ScreenDc,nScreenWidth, nScreenHeight);
  SelectObject(hCaptureDC,bmp.Handle);

  BitBlt(hCaptureDC,0,0,nScreenWidth,nScreenHeight,ScreenDc,0,0,SRCCOPY);
  bmp.SaveToFile(fileName);

  ReleaseDC(GetDesktopWindow,ScreenDc);
  DeleteDC(hCaptureDC);
  bmp.Free;
end;

通过上面这一步,我们可以很容易联想到用来抓取任何一个控件的表面图象,函数如下:

procedure CaptureControl(Control: TWinControl;const FileName: string);overload;
var
  ControlWidth,ControlHeight: integer;
  ControlDc,hCaptureDC: HDC;
  bmp: TBitmap;
begin
  ControlWidth := Control.ClientWidth;
  ControlHeight := Control.ClientHeight;
  ControlDc := GetDC(Control.Handle);
  hCaptureDC := CreateCompatibleDC(ControlDc);
  bmp := TBitmap.Create;
  bmp.Handle :=CreateCompatibleBitmap(ControlDc,ControlWidth,ControlHeight);
  SelectObject(hCaptureDC,bmp.Handle);

  BitBlt(hCaptureDC,0,0,ControlWidth,ControlHeight,ControlDc,0,0,SRCCOPY);
  bmp.SaveToFile(fileName);

  ReleaseDC(GetDesktopWindow,ControlDc);
  DeleteDC(hCaptureDC);
  bmp.Free;
end;

上一页1234下一页

Tags:使用 函数 
作者:不得闲 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
本类推荐
  • 没有
本类固顶
  • 没有
  • 盒子文章(www.2ccc.com) © 2024 版权所有 All Rights Reserved.
  • 沪ICP备05001939号