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. 0MQ 事件驱动 以及 poller

    底层IO事件,以及借用socket poller的上层0MQ socket事件. 先来看用于底层和上层的两种poller. 这是用于底层io事件的poller_t,每个socket_base_t都关联 ...

  2. 机器学习 TensorFlow 实现智能鉴黄

    前言 最近在做一款图床服务,关注公号的小伙伴一定记得小柒曾说过,会在周末放出的,不好意思放大家鸽子了.之所以一直没敢放出,是因为鉴黄接口一直没调试好,虽然我对公号的小伙伴百分之百信任,奈何互联网鱼龙混 ...

  3. Video的自我学习

    直播原理 视频协议 HLS协议  [主要是直播方面(好用,但延时)] HTTP Live Streaming(缩写是HLS)是一个由苹果公司提出的基于HTTP的流媒体网络传输协议. 是苹果公司Quic ...

  4. elasticsearch安装踩坑记

    ES的安装与启动时问题解决 环境: ​ 系统环境:CentOS7 ​ JDK:jdk-8u131-linux-x64.tar.gz 不可以通过Root用户来启动ES 通过上面的错误提示可以看出,can ...

  5. PowerMock学习(五)之Verifying的使用

    前言 Verifying是一个非常强大的测试工具,在mock系列框架中使用广泛,主要用于验证方法是否被调用,下面将举例说明. 场景 模拟这样一个场景,通过Dao查询学生,如果存在更新原来学生,不存在则 ...

  6. Spring Cloud Alibaba(四)实现Dubbo服务消费

    本项目演示如何使用 Spring Cloud Alibaba 完成 Dubbo 的RPC调用. Spring Cloud与Dubbo Spring Cloud是一套完整的微服务架构方案 Dubbo是国 ...

  7. 图解 Spring:HTTP 请求的处理流程与机制【4】

    4. HTTP 请求在 Spring 框架中的处理流程 在穿越了 Web 容器和 Web 应用之后,HTTP 请求将被投送到 Spring 框架,我们继续剖析后续流程.Web 应用与 Spring M ...

  8. C语言基础——进制转换 / 数据表示

    第一部分:进制转换 二进制:由0~1构成,逢2进1 八进制:由0~7构成,逢8进1 十六进制:由0~9.A~F构成,逢16进1 两个基本概念 基数:n进制基数为n 123.4 = 1*10^2 + 2 ...

  9. 请停止编写这么多的for循环!

    在这篇文章中,我想和你一起回到基础知识,并讨论 Java 中的 for 循环.老实说,我正在为自己写这篇博客文章,因为我也会这样做.从 Java 8 开始,我们不必在 Java 中编写太多 for 循 ...

  10. plot()与dev 函数族的使用

    1. plot()的类型选择 plot()函数,属于graphics包中. plot(a,b,type="value") type:以什么样的形式来画a,b之间的关系: ·&quo ...