forked from Trevor3000/RemoteControl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreenUtil.cs
More file actions
55 lines (50 loc) · 1.9 KB
/
Copy pathScreenUtil.cs
File metadata and controls
55 lines (50 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Windows.Forms;
namespace RemoteControl.Client
{
class ScreenUtil
{
/// <summary>
/// 捕获屏幕
/// <para>不支持未登陆时截图</para>
/// </summary>
/// <returns></returns>
public static Image CaptureScreen1()
{
Image myImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics g = Graphics.FromImage(myImage);
g.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height));
IntPtr pDC = g.GetHdc();
g.ReleaseHdc(pDC);
return myImage;
}
[DllImport("Gdi32.dll")]
public extern static int BitBlt(IntPtr hDC, int x, int y, int nWidth, int nHeight, IntPtr hSrcDC, int xSrc, int ySrc, int dwRop);
/// <summary>
/// 捕获屏幕
/// <para>支持未登陆时截图</para>
/// </summary>
/// <returns></returns>
public static Image CaptureScreen2()
{
int width = Screen.PrimaryScreen.Bounds.Width;
int height = Screen.PrimaryScreen.Bounds.Height;
Bitmap screenCopy = new Bitmap(width, height);
using (Graphics gDest = Graphics.FromImage(screenCopy))
{
Graphics gSrc = Graphics.FromHwnd(IntPtr.Zero);
IntPtr hSrcDC = gSrc.GetHdc();
IntPtr hDC = gDest.GetHdc();
int retval = BitBlt(hDC, 0, 0, width, height, hSrcDC, 0, 0, (int)(CopyPixelOperation.SourceCopy | CopyPixelOperation.CaptureBlt));
gDest.ReleaseHdc();
gSrc.ReleaseHdc();
}
return screenCopy;
}
}
}