Repository navigation
Expand file tree
/
Copy pathScreenshot.cs
More file actions
executable file
·130 lines (119 loc) · 5.04 KB
/
Copy pathScreenshot.cs
File metadata and controls
executable file
·130 lines (119 loc) · 5.04 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
namespace RemoteControl.Drawing
{
public class Screenshot
{
[DllImport("user32.dll")]
static extern bool GetCursorInfo(out CURSORINFO pci);
private const Int32 CURSOR_SHOWING = 0x00000001;
[StructLayout(LayoutKind.Sequential)]
struct POINT
{
public Int32 x;
public Int32 y;
}
[StructLayout(LayoutKind.Sequential)]
struct CURSORINFO
{
public Int32 cbSize;
public Int32 flags;
public IntPtr hCursor;
public POINT ptScreenPos;
}
public Image GetFullScreenImage(VideoParameters v)
{
try
{
System.Drawing.Image MyImage = new Bitmap((int)SystemParameters.VirtualScreenWidth, (int)SystemParameters.VirtualScreenHeight);
CURSORINFO pci;
pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
GetCursorInfo(out pci);
Graphics g = Graphics.FromImage(MyImage);
g.CopyFromScreen(new System.Drawing.Point(0, 0), new System.Drawing.Point(0, 0), new System.Drawing.Size((int)SystemParameters.VirtualScreenWidth, (int)SystemParameters.VirtualScreenHeight));
System.Windows.Forms.Cursor cur = new System.Windows.Forms.Cursor(pci.hCursor);
cur.Draw(g, new System.Drawing.Rectangle(pci.ptScreenPos.x - 10, pci.ptScreenPos.y - 10, cur.Size.Width, cur.Size.Height));
Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
MyImage.RotateFlip(RotateFlipType.Rotate90FlipNone);
Image img = MyImage.GetThumbnailImage(v.Height, v.Width, myCallback, IntPtr.Zero);
return img;
}
catch
{
throw;
}
}
public Image GetRectangleScreenshot(VideoParameters v)
{
try
{
int videoWidth = (int)SystemParameters.VirtualScreenWidth;
int videoHeight = (int)SystemParameters.VirtualScreenHeight;
System.Drawing.Image MyImage = new Bitmap(v.Width,v.Height );
CURSORINFO pci;
pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
GetCursorInfo(out pci);
Graphics g = Graphics.FromImage(MyImage);
int px = 0;
int py = 0;
int wx= videoWidth - pci.ptScreenPos.x;
int wy = videoHeight - pci.ptScreenPos.y;
int mouseX=0;
int mouseY=0;
if(pci.ptScreenPos.x>v.Width && wx<v.Width)
{
px = videoWidth - v.Width;
mouseX=pci.ptScreenPos.x-(videoWidth - v.Width);
}
else if(pci.ptScreenPos.x<v.Width && wx>v.Width)
{
px = 0;
mouseX=pci.ptScreenPos.x;
}
else if(pci.ptScreenPos.x-(v.Width/2)>0 && pci.ptScreenPos.x+(v.Width/2)<videoWidth)
{
px = pci.ptScreenPos.x - (v.Width / 2);
mouseX=v.Width/2;
}
if(pci.ptScreenPos.y>v.Height && wy<v.Height)
{
py = videoHeight - v.Height;
mouseY=pci.ptScreenPos.y-(videoHeight-v.Height);
}
else if (pci.ptScreenPos.y < v.Height && wy > v.Height)
{
py = 0;
mouseY=pci.ptScreenPos.y;
}
else if(pci.ptScreenPos.y-(v.Height/2)>0 && pci.ptScreenPos.y+(v.Height/2)<videoHeight)
{
py = pci.ptScreenPos.y - (v.Height / 2);
mouseY=v.Height/2;
}
g.CopyFromScreen(new System.Drawing.Point(px, py), new System.Drawing.Point(0, 0), new System.Drawing.Size(v.Width, v.Height));
System.Windows.Forms.Cursor cur = new System.Windows.Forms.Cursor(pci.hCursor);
cur.Draw(g, new System.Drawing.Rectangle(mouseX,mouseY, cur.Size.Width, cur.Size.Height));
Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
MyImage.RotateFlip(RotateFlipType.Rotate90FlipNone);
Image img = MyImage.GetThumbnailImage(v.Height, v.Width, myCallback, IntPtr.Zero);
//img.Save(@"D:\1.jpg");
return img;
}
catch
{
throw;
}
}
public static bool ThumbnailCallback()
{
return false;
}
}
}