c#截取后台窗口的图片,自测可用,据说性能很一般,用用吧

         struct RECT
{
public int Left; // x position of upper-left corner
public int Top; // y position of upper-left corner
public int Right; // x position of lower-right corner
public int Bottom; // y position of lower-right corner
}
public static Bitmap GetWindow(IntPtr hWnd)
{
IntPtr hscrdc = GetWindowDC(hWnd);
RECT rect = new RECT();
GetWindowRect(hWnd, out rect);
IntPtr hbitmap = CreateCompatibleBitmap(hscrdc, rect.Right - rect.Left, rect.Bottom - rect.Top);
IntPtr hmemdc = CreateCompatibleDC(hscrdc);
SelectObject(hmemdc, hbitmap);
PrintWindow(hWnd, hmemdc, );
Bitmap bmp = Bitmap.FromHbitmap(hbitmap);
DeleteDC(hscrdc);
DeleteDC(hmemdc);
return bmp;
} //API声明 [DllImport("user32.dll")]
private static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect); [DllImport("gdi32.dll")]
public static extern IntPtr CreateDC(
string lpszDriver, // driver name驱动名
string lpszDevice, // device name设备名
string lpszOutput, // not used; should be NULL
IntPtr lpInitData // optional printer data
); [DllImport("gdi32.dll")]
public static extern int BitBlt(
IntPtr hdcDest, // handle to destination DC目标设备的句柄
int nXDest, // x-coord of destination upper-left corner目标对象的左上角的X坐标
int nYDest, // y-coord of destination upper-left corner目标对象的左上角的Y坐标
int nWidth, // width of destination rectangle目标对象的矩形宽度
int nHeight, // height of destination rectangle目标对象的矩形长度
IntPtr hdcSrc, // handle to source DC源设备的句柄
int nXSrc, // x-coordinate of source upper-left corner源对象的左上角的X坐标
int nYSrc, // y-coordinate of source upper-left corner源对象的左上角的Y坐标
UInt32 dwRop // raster operation code光栅的操作值
); [DllImport("gdi32.dll")]
public static extern IntPtr CreateCompatibleDC(
IntPtr hdc // handle to DC
); [DllImport("gdi32.dll")]
public static extern IntPtr CreateCompatibleBitmap(
IntPtr hdc, // handle to DC
int nWidth, // width of bitmap, in pixels
int nHeight // height of bitmap, in pixels
); [DllImport("gdi32.dll")]
public static extern IntPtr SelectObject(
IntPtr hdc, // handle to DC
IntPtr hgdiobj // handle to object
); [DllImport("gdi32.dll")]
public static extern int DeleteDC(
IntPtr hdc // handle to DC
); [DllImport("user32.dll")]
public static extern bool PrintWindow(
IntPtr hwnd, // Window to copy,Handle to the window that will be copied.
IntPtr hdcBlt, // HDC to print into,Handle to the device context.
UInt32 nFlags // Optional flags,Specifies the drawing options. It can be one of the following values.
); [DllImport("user32.dll")]
public static extern IntPtr GetWindowDC(
IntPtr hwnd
);

c#截取后台窗口的图片的更多相关文章

  1. jQuery弹出窗口浏览图片

    效果预览:http://keleyi.com/keleyi/phtml/jqtexiao/3.htm HTML文件代码: <!DOCTYPE HTML> <html> < ...

  2. android通过Canvas和Paint截取无锯齿圆形图片

    一个通过Canvas和Paint截取无锯齿圆形图片. /** * 根据原图和变长绘制圆形图片 * * @param source * @param min * @return */ public st ...

  3. Qt添加窗口背景图片、Label图片显示、、Label文字显示

    一.添加窗口背景图片 重写MainWindow绘制事件 void MainWindow::paintEvent(QPaintEvent *event) { QPainter painter(this) ...

  4. Webdriver中实现区域截图的方式以及如何截取frame中的图片

    import java.awt.Rectangle;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOE ...

  5. php截取后台登陆密码的代码

    php截取后台登陆密码的代码,很多时候黑客留了这样的代码,大家一定要注意下if($_POST[loginsubmit]!=){ //判断是否点了登陆按钮 $sb=user:.$_POST[userna ...

  6. C# WebBrowser的DrawToBitmap方法 截取网页保存为图片

    bool mark = true;         private void btnOpen_Click(object sender, EventArgs e)         {           ...

  7. 使用Selenium截取网页上的图片

    前言 同样是为了刷课,没想到工作后依然和大学一样逃脱不了需要刷网课的命运-- 正文 直接说干货了,截取图片,需要截取的图片是什么图片大家都懂(说的就是你,验证码),其他图片的话不需要截取,直接拿到地址 ...

  8. pyside 为窗口添加图片

    有时我们需要添加一些图片到窗口上,下面给一个通过QLable实现的方法. 这里需要注意的是,当你启用多线程时,方法调用的setPixmap,会导致qt报出一个线程安全错误. 因此,让这个绘图工作尽量在 ...

  9. MFC 设置窗口背景图片

    //在Onpaint函数中加入如下代码 //----------给窗口设置背景图片---------------------------- CPaintDC dc(this); CRect myrec ...

随机推荐

  1. LoadRunner中的90%响应时间

    LoadRunner中的90%响应时间是什么意思?这个值在进行性能分析时有什么作用? 为什么要有90%用户响应时间? 这个跟超女.舞林大会等比赛那样在比赛后都要去掉一个最高分一个最低分在取平均值有点类 ...

  2. 2019-9-25:渗透测试,基础学习,medusa爆破学习

    Medusa(美杜莎)暴力破解使用 该文章仅供学习,利用方法来自网络文章,仅供参考 一.简介 medusa(美杜莎)是一个速度快,支持大规模并行,模块化,爆破登陆,可以同时对多个主机,用户或是密码执行 ...

  3. day03_正则表达式

    1.数据分类 数据的分类 ​ 定义:数据以行为单位,每一个数据表示一个实体的信息.每一行数据的属性都是一样的. ​ 常见的结构化数据为关系型数据库存储数据. 半结构化数据 ​ 定义:结构化数据的另一种 ...

  4. 九、Spring Boot 优雅的实现CORS跨域

    前言 我们的springboot 架手架已经包含了mysql,redis,定时任务,邮件服务,短信服务,文件上传下载,以及docker-compose 构建镜像等等. 接下来让我们解决另一个常见的问题 ...

  5. 大白话OSI七层协议

    目录 一.物理层 二.数据链路层 2.1 以太网协议 2.2 Mac地址 2.3 广播地址 三.网络层 3.1 IP协议详解 3.1.1 IP地址的两部分 3.2 子网掩码详解 3.3 IP数据包详解 ...

  6. 2019-2020-11 20199317 《Linux内核原理与分析》 第十一周作业

    ShellShock 攻击实验 1  ShellShock 简介      Shellshock,又称Bashdoor,是在Unix中广泛使用的Bash shell中的一个安全漏洞,首次于2014年9 ...

  7. ThinkPHP3.2.2实现持久登录(记住我)功能的方法

    实现持久登录,即用户在登录时,勾选了"记住我"之后,无论是否关闭浏览器,只要不退出登录,在指定的时间内始终保持登录状态(缺点是在另一台电脑上登录过后,之前那台电脑就不能继续保持登录 ...

  8. 外键(foreign key)的使用及其优缺点

    如果公共关键字在一个关系中是主关键字,那么这个公共关键字被称为另一个关系的外键.由此可见,外键表示了两个关系之间的相关联系.以另一个关系的外键作主关键字的表被称为主表,具有此外键的表被称为主表的从表. ...

  9. Hive Hadoop 解析 orc 文件

    解析 orc 格式 为 json 格式: ./hive --orcfiledump -d <hdfs-location-of-orc-file> 把解析的 json 写入 到文件 ./hi ...

  10. 消息通知机制(NSNotification和NSNotificationCenter)

    作者:FlyElephant 出处:http://www.cnblogs.com/xiaofeixiang iOS中委托模式和消息机制基本上开发中用到的比较多,一般最开始页面传值通过委托实现的比较多, ...