代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
C#截屏
作者:
xqf222
/ 发布于
2014/2/25
/
432
using System; using System.Runtime.InteropServices; using System.Drawing; using System.Drawing.Imaging; namespace CSharpChat { /// <summary> /// ScreenCameraClass 的摘要说明。 /// </summary> public class ScreenCameraClass { public ScreenCameraClass() { // // TODO: 在此处添加构造函数逻辑 // } /**//// <summary> /// Creates an Image object containing a screen shot of the entire desktop? /// </summary> /// <returns></returns> public Image CaptureScreen() { return CaptureWindow( User32.GetDesktopWindow() ); } /**//// <summary> /// Creates an Image object containing a screen shot of a specific window? /// </summary> /// <param name="handle">The handle to the window. (In windows forms, this is obtained by the Handle property)</param> /// <returns></returns> public Image CaptureWindow(IntPtr handle) { // get te hDC of the target window IntPtr hdcSrc = User32.GetWindowDC(handle); // get the size User32.RECT windowRect = new User32.RECT(); User32.GetWindowRect(handle,ref windowRect); int width = windowRect.right - windowRect.left; int height = windowRect.bottom - windowRect.top; // create a device context we can copy to IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc); // create a bitmap we can copy it to, // using GetDeviceCaps to get the width/height IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc,width,height); // select the bitmap object IntPtr hOld = GDI32.SelectObject(hdcDest,hBitmap); // bitblt over GDI32.BitBlt(hdcDest,0,0,width,height,hdcSrc,0,0,GDI32.SRCCOPY); // restore selection GDI32.SelectObject(hdcDest,hOld); // clean up GDI32.DeleteDC(hdcDest); User32.ReleaseDC(handle,hdcSrc); // get a .NET image object for it Image img = Image.FromHbitmap(hBitmap); // free up the Bitmap object GDI32.DeleteObject(hBitmap); return img; } /**//// <summary> /// Captures a screen shot of a specific window, and saves it to a file? /// </summary> /// <param name="handle"></param> /// <param name="filename"></param> /// <param name="format"></param> public void CaptureWindowToFile(IntPtr handle, string filename, ImageFormat format) { Image img = CaptureWindow(handle); img.Save(filename,format); } /**//// <summary> /// Captures a screen shot of the entire desktop, and saves it to a file? /// </summary> /// <param name="filename"></param> /// <param name="format"></param> public void CaptureScreenToFile(string filename, ImageFormat format) { Image img = CaptureScreen(); img.Save(filename,format); } /**//// <summary> /// Helper class containing Gdi32 API functions /// </summary> private class GDI32 { public const int SRCCOPY = 0x00CC0020; // BitBlt dwRop parameter [DllImport("gdi32.dll")] public static extern bool BitBlt(IntPtr hObject,int nXDest,int nYDest, int nWidth,int nHeight,IntPtr hObjectSource, int nXSrc,int nYSrc,int dwRop); [DllImport("gdi32.dll")] public static extern IntPtr CreateCompatibleBitmap(IntPtr hDC,int nWidth, int nHeight); [DllImport("gdi32.dll")] public static extern IntPtr CreateCompatibleDC(IntPtr hDC); [DllImport("gdi32.dll")] public static extern bool DeleteDC(IntPtr hDC); [DllImport("gdi32.dll")] public static extern bool DeleteObject(IntPtr hObject); [DllImport("gdi32.dll")] public static extern IntPtr SelectObject(IntPtr hDC,IntPtr hObject); } /**//// <summary> /// Helper class containing User32 API functions /// </summary> private class User32 { [StructLayout(LayoutKind.Sequential)] public struct RECT { public int left; public int top; public int right; public int bottom; } [DllImport("user32.dll")] public static extern IntPtr GetDesktopWindow(); [DllImport("user32.dll")] public static extern IntPtr GetWindowDC(IntPtr hWnd); [DllImport("user32.dll")] public static extern IntPtr ReleaseDC(IntPtr hWnd,IntPtr hDC); [DllImport("user32.dll")] public static extern IntPtr GetWindowRect(IntPtr hWnd,ref RECT rect); } } }
试试其它关键字
截屏
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
xqf222
贡献的其它代码
(
82
)
.
VB编写的登录局域网内的sql2000数据库服务器
.
ASP .NET登录界面用户验证码
.
VB操作ACCESS数据库
.
批量发送邮件程序
.
批量抓取网页代码中的HTTP和邮件地址
.
禁止站外提交参数测试
.
FTP网站文件到本地的
.
调用对应的应用程打开文件
.
抓取邮件内容解析
.
保存文件时候的弹出选择要保存的文件夹带新建文件夹效
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3