window form 截屏
来源:互联网 发布:淘宝正品代购推荐 编辑:程序博客网 时间:2024/06/17 18:16
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")] private static extern bool BitBlt( IntPtr hdcDest, // 目标 DC的句柄 int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, // 源DC的句柄 int nXSrc, int nYSrc, System.Int32 dwRop // 光栅的处理数值 ); [System.Runtime.InteropServices.DllImport("gdi32.dll")] public static extern IntPtr CreateDC(string driver, string device, IntPtr res1, IntPtr res2); private void button1_Click(object sender, EventArgs e) { GetScreen1(); GetScreen2(); } public static void GetScreen1() { //截取屏幕内容 Size screen = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); Bitmap memoryImage = new Bitmap(screen.Width, screen.Height); Graphics memoryGraphics = Graphics.FromImage(memoryImage); // memoryGraphics.CopyFromScreen(0, 0, 0, 0, screen, CopyPixelOperation.SourceCopy); memoryGraphics.CopyFromScreen(0, 0, 0, 0, screen); //memoryImage memoryImage.Save(@"screen.jpg", ImageFormat.Jpeg); MemoryStream data = new MemoryStream(); // memoryImage.Save(data, ImageFormat.Png); } public static void GetScreen2() { //截取屏幕内容 Rectangle rect = new Rectangle(); // rect = Screen.GetWorkingArea(this); rect = Screen.PrimaryScreen.Bounds; //创建一个以当前屏幕为模板的图象 IntPtr dcTmp = CreateDC("DISPLAY", "DISPLAY", (IntPtr)null, (IntPtr)null); Graphics g1 = Graphics.FromHdc(dcTmp); //创建以屏幕大小为标准的位图 Image MyImage = new Bitmap(rect.Width, rect.Height, g1); Graphics g2 = Graphics.FromImage(MyImage); //得到屏幕的DC IntPtr dc1 = g1.GetHdc(); //得到Bitmap的DC IntPtr dc2 = g2.GetHdc(); //调用此API函数,实现屏幕捕获 // BitBlt(dc2, 0, 0, rect.Width, rect.Height, dc1, 0, 0, 13369376); BitBlt(dc2, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, dc1, 0, 0, 13369376); //释放掉屏幕的DC g1.ReleaseHdc(dc1); //释放掉Bitmap的DC g2.ReleaseHdc(dc2); //以JPG文件格式来保存 MyImage.Save("text.jpg", ImageFormat.Jpeg); string a = "当前屏幕已经保存"; MessageBox.Show(a); }}
}
阅读全文
0 0
- window form 截屏
- Window Form Printer
- window form 练习使用datagridview
- 使用window.open传递form
- 多线程响应与 Window Form
- window form input validation && errorProvider
- Custom data binding, window form
- window下面的form自适应
- easyui window open form disableValidation
- # WinForm开发系列 - Form/Window
- oracle form builder :关于Form/block/canvas/window
- Window、document、form(属性、方法、事件)
- Window、document、form(属性、方法、事件)
- C#语言window form 编写“资源管理器”
- Window、document、form(属性、方法、事件)
- EXT form表单提交 window中显示
- Window、document、form(属性、方法、事件)
- C# WinForm开发系列 - Form/Window
- 实现1+2+3...+n,要求不能使用乘除法、循环、条件判断、选择相关的关键字(for、while、if、else、switch、case)。
- 对象的初始化块。对象初始化过程
- 创建版本库
- AFNetworing同步网络请求?
- tornado提供图像服务
- window form 截屏
- iOS 加图片的动画退出应用
- oracle中exists
- Laravel队列处理
- React Native Navigator
- JSP Cookie 处理
- OpenGL内核模式学习笔记第1篇——开发环境的配置
- 静态工厂方法代替构造器
- 记录我的第一篇