没有合适的资源?快使用搜索试试~ 我知道了~
API 桌面截图实例
4星 · 超过85%的资源 需积分: 9 68 下载量 185 浏览量
2008-11-26
17:32:08
上传
评论 1
收藏 6KB TXT 举报
温馨提示
试读
6页
主要内容是c#进行全屏抓图和窗口抓图,非常详细。带有详细实例和注释
资源推荐
资源详情
资源评论
主要内容是进行全屏抓图和窗口抓图
理论
主要函数
BOOL BitBlt(
HDC hdcDest, // handle to destination DC//使用目标Image的DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
HDC hdcSrc, // handle to source DC//待绘制设备的DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
DWORD dwRop // raster operation code//操作标志,取13369376,表示SRCCOPY
);
可将原设备COPY绘制到目标设备上,实现抓图
实现
1.全屏幕抓图
主要是得到Desktop的设备DC,所需函数原型如下
static CWnd* PASCAL GetDesktopWindow( );
HDC GetWindowDC( HWND hWnd // handle to window );
可以通过GetWindowDC(GetDesktopWindows())得到Desktop的DC,直接绘制即可
在源码中的实现是ToolStripMenuItemCutFullScreen_Click()函数
2.当前窗口抓图
直接得到当前窗口的DC就可以了,GetWindowDC(this.Handle);
在源码中的实现是ToolStripMenuItemCutCurrentWindows_Click()函数
3.使用快捷键抓取当前活动窗口
static CWnd* PASCAL GetForegroundWindow( );
用这个函数得到活动窗口的指针,用GetWindowDC(new IntPtr(GetForegroundWindow()))就可以得到窗口DC
还需要得到窗口的大小,函数
BOOL GetWindowRect(
理论
主要函数
BOOL BitBlt(
HDC hdcDest, // handle to destination DC//使用目标Image的DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
HDC hdcSrc, // handle to source DC//待绘制设备的DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
DWORD dwRop // raster operation code//操作标志,取13369376,表示SRCCOPY
);
可将原设备COPY绘制到目标设备上,实现抓图
实现
1.全屏幕抓图
主要是得到Desktop的设备DC,所需函数原型如下
static CWnd* PASCAL GetDesktopWindow( );
HDC GetWindowDC( HWND hWnd // handle to window );
可以通过GetWindowDC(GetDesktopWindows())得到Desktop的DC,直接绘制即可
在源码中的实现是ToolStripMenuItemCutFullScreen_Click()函数
2.当前窗口抓图
直接得到当前窗口的DC就可以了,GetWindowDC(this.Handle);
在源码中的实现是ToolStripMenuItemCutCurrentWindows_Click()函数
3.使用快捷键抓取当前活动窗口
static CWnd* PASCAL GetForegroundWindow( );
用这个函数得到活动窗口的指针,用GetWindowDC(new IntPtr(GetForegroundWindow()))就可以得到窗口DC
还需要得到窗口的大小,函数
BOOL GetWindowRect(
HWND hWnd,
LPRECT lpRect
);
直接提供窗口指针和矩形对象就可以了
4.快捷键使用在上一篇上有,这里使用WIN+T作为抓图热键
Tips:
图片超过窗口时显示滚动条的实现
先使用一个Panel,在里面放一个PictureBox,然后把Panel的AutoScroll设为True就OK
--------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace 窗口抓图
{
public partial class Form1 : Form
{
#region DLLImport
[DllImport("user32.dll")]
public extern static IntPtr GetDesktopWindow();
LPRECT lpRect
);
直接提供窗口指针和矩形对象就可以了
4.快捷键使用在上一篇上有,这里使用WIN+T作为抓图热键
Tips:
图片超过窗口时显示滚动条的实现
先使用一个Panel,在里面放一个PictureBox,然后把Panel的AutoScroll设为True就OK
--------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace 窗口抓图
{
public partial class Form1 : Form
{
#region DLLImport
[DllImport("user32.dll")]
public extern static IntPtr GetDesktopWindow();
剩余5页未读,继续阅读
资源评论
- Soble282012-02-02API截图速度不够快
huangzhiyong520
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功