-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScreenshotter.cs
82 lines (68 loc) · 2.51 KB
/
Screenshotter.cs
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
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
namespace TrackPrintScreen
{
class Screenshotter
{
ImageFormat imageFormat;
Options options;
public Screenshotter(Options options)
{
imageFormat = ImageFormat.Jpeg;
this.options = options;
}
public void Shot(bool special = false)
{
DateTime now = DateTime.Now;
string path = options.FolderPath;
char lastChar = path[path.Length - 1];
if(lastChar != '\\' || lastChar != '/')
{
path += "\\";
}
path += now.ToString("yy-MM-dd HH-mm-ss");
if (special) path = path + " 1 ";
path += ".jpg";
int screenLeft = SystemInformation.VirtualScreen.Left;
int screenTop = SystemInformation.VirtualScreen.Top;
int screenWidth = SystemInformation.VirtualScreen.Width;
int screenHeight = SystemInformation.VirtualScreen.Height;
using (Bitmap bitmap = new Bitmap(screenWidth, screenHeight))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(screenLeft, screenTop, 0, 0, bitmap.Size);
}
ImageCodecInfo myImageCodecInfo;
Encoder myEncoder;
EncoderParameter myEncoderParameter;
EncoderParameters myEncoderParameters;
myImageCodecInfo = GetEncoderInfo("image/jpeg");
myEncoder = Encoder.Quality;
myEncoderParameters = new EncoderParameters(1);
// Save the bitmap as a JPEG file with quality level 75.
myEncoderParameter = new EncoderParameter(myEncoder, 75L);
myEncoderParameters.Param[0] = myEncoderParameter;
bitmap.Save(path, myImageCodecInfo, myEncoderParameters);
}
}
public void UpdateOptions(Options options)
{
this.options = options;
}
private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}
}
}