日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

一个截屏的例子

發布時間:2023/12/31 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 一个截屏的例子 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1using System;
2using System.Drawing;
3using System.Collections;
4using System.ComponentModel;
5using System.Windows.Forms;
6using System.Data;
7using System.Runtime.InteropServices;
8
9namespace takeScreen
10{
11/**//// <summary>
12/// Form1 的摘要說明。
13/// </summary>

14 public class frmScreen : System.Windows.Forms.Form
15{
16private System.Windows.Forms.Button btnOK;
17/**//// <summary>
18/// 必需的設計器變量。
19/// </summary>

20 private System.ComponentModel.Container components = null;
21
22public frmScreen()
23{
24//
25// Windows 窗體設計器支持所必需的
26//
27 InitializeComponent();
28
29//
30// TODO: 在 InitializeComponent 調用后添加任何構造函數代碼
31//
32 }

33
34/**//// <summary>
35/// 清理所有正在使用的資源。
36/// </summary>

37 protected override void Dispose( bool disposing )
38{
39if( disposing )
40{
41if (components != null)
42{
43 components.Dispose();
44 }

45 }

46base.Dispose( disposing );
47 }

48
49Windows 窗體設計器生成的代碼#region Windows 窗體設計器生成的代碼
50/**//// <summary>
51/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
52/// 此方法的內容。
53/// </summary>

54 private void InitializeComponent()
55{
56 System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmScreen));
57this.btnOK = new System.Windows.Forms.Button();
58this.SuspendLayout();
59//
60// btnOK
61//
62 this.btnOK.BackColor = System.Drawing.Color.Transparent;
63this.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
64this.btnOK.ForeColor = System.Drawing.Color.White;
65this.btnOK.Location = new System.Drawing.Point(48, 56);
66this.btnOK.Name = "btnOK";
67this.btnOK.TabIndex = 1;
68this.btnOK.Text = "截屏";
69this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
70//
71// frmScreen
72//
73 this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
74this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
75this.ClientSize = new System.Drawing.Size(180, 140);
76this.Controls.Add(this.btnOK);
77this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
78this.Name = "frmScreen";
79this.Text = "抓屏";
80this.ResumeLayout(false);
81
82 }

83#endregion

84
85/**//// <summary>
86/// 應用程序的主入口點。
87/// </summary>

88 [STAThread]
89static void Main()
90{
91 Application.Run(new frmScreen());
92 }

93
94private void btnOK_Click(object sender, System.EventArgs e)
95{
96//創建當前屏幕的DC對象
97 IntPtr ptr = CreateDC("DISPLAY",null,null,(IntPtr)null );
98 Graphics currentG = Graphics.FromHdc(ptr);
99//創建以屏幕大小為標準的位圖對象
100 Image myImage = new Bitmap( Screen.PrimaryScreen.WorkingArea.Width,Screen.PrimaryScreen.WorkingArea.Height, currentG );
101 Graphics imageG = Graphics.FromImage( myImage );
102//得到屏幕DC
103 IntPtr screenPtr = currentG.GetHdc();
104//得到位圖的DC
105 IntPtr imagePtr = imageG.GetHdc();
106//截屏
107 BitBlt( imagePtr,0,0,Screen.PrimaryScreen.WorkingArea.Width,Screen.PrimaryScreen.WorkingArea.Height,screenPtr,0,0,13369376 );
108
109//釋放DC
110 currentG.ReleaseHdc( screenPtr );
111 imageG.ReleaseHdc( imagePtr );
112
113 myImage.Save(@"C:\screen.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
114 MessageBox.Show("ok");
115this.Close();
116this.Dispose();
117
118 }

119
120 [DllImport("GDI32.Dll")]
121private static extern bool BitBlt( IntPtr hdcDest,int nXDest, int nYDest,int nWidth,int nHeight,IntPtr hdcSrc,int nXSrc,int nYSrc,Int32 dwRop);
122 [DllImport("GDI32.Dll")]
123private static extern IntPtr CreateDC( string lpszDrive, string lpszDevice, string lpszOutput, IntPtr lplnitData );
124
125 }

126}

127

轉載于:https://www.cnblogs.com/bluedream/archive/2005/04/20/141198.html

總結

以上是生活随笔為你收集整理的一个截屏的例子的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。