当前位置:网站首页>WinForm screenshot save C code
WinForm screenshot save C code
2022-07-27 19:02:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack
The code is as follows :
1 using System.Runtime.InteropServices;
2 using System.Drawing.Imaging;
3
4
5
6 [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
7 private static extern bool BitBlt(
8
9 IntPtr hdcDest, // The goal is DC The handle of
10 int nXDest,
11 int nYDest,
12 int nWidth,
13 int nHeight,
14 IntPtr hdcSrc, // Source DC The handle of
15 int nXSrc,
16 int nYSrc,
17 System.Int32 dwRop // Processing value of grating
18 );
19
20
21
22 private void button1_Click(object sender, System.EventArgs e)
23 {
24 // Get the current screen size http://www.cnblogs.com/roucheng/
25 Rectangle rect = new Rectangle ( ) ;
26 rect = Screen.GetWorkingArea ( this ) ;
27 // Create an image based on the current screen
28 Graphics g1 = this.CreateGraphics ( ) ;
29 // Create a bitmap based on screen size
30 Image MyImage = new Bitmap ( rect.Width , rect.Height , g1 ) ;
31 Graphics g2 = Graphics.FromImage ( MyImage ) ;
32 // Get the screen DC
33 IntPtr dc1 = g1.GetHdc ( ) ;
34 // obtain Bitmap Of DC
35 IntPtr dc2 = g2.GetHdc ( ) ;
36 // Call this API function , Realize screen capture
37 BitBlt ( dc2 , 0 , 0 , rect.Width , rect.Height , dc1 , 0 , 0 , 13369376 ) ;
38 // Release the screen DC
39 g1.ReleaseHdc ( dc1 ) ;
40 // release Bitmap Of DC
41 g2.ReleaseHdc ( dc2 ) ;
42 // With JPG File format to save
43 MyImage.Save ( @"c:/Capture.jpg" , ImageFormat.Jpeg );
44 MessageBox.Show ( " The current screen has been saved as C Discoid capture.jpg file !" ) ;
45 }Implemented in the project :http://hovertree.com/h/bjaf/76q5yeli.htm
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/120703.html Link to the original text :https://javaforall.cn
边栏推荐
猜你喜欢

MySQL 04 advanced query (II)

NPM's ID card and dependence

MySQL 05 stored procedure

Multifunctional wireless remote control moxibustion instrument chip dltap703sd

MySQL 06 事务、视图、索引、备份和恢复

【npm】 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。

Blog Garden beautification tutorial

NPM basic use

订单的提交

MySQL 04 高级查询(二)
随机推荐
Product recommendation and classified product recommendation
Latex使用-控制表格或者图形的显示位置
Arrays and objects in JS
MySQL create event execution task
C static method and non static method
Resource for NS2 beginner
MicaZ+Tinyos学习笔记(1)
MySQL 03 advanced query (I)
Latex使用--subfigure竖排图形
MySQL 06 transaction, view, index, backup and recovery
Express get/post/delete... Request
Household mute mosquito repellent lamp chip-dltap703sd-jericho
Overview of Baidu map technology, and application development of basic API and webapi
WORD 2007+使用技巧
Imitation thread deduction
`this.$emit` 子组件给父组件传递多个参数
微机原理学习笔记-常见寻址方式
LeetCode 刷题 第三天
MySQL 04 高级查询(二)
Netred RGB mirror light touch chip-dlt8s15b-jericho