-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
218 lines (196 loc) · 7.95 KB
/
Program.cs
File metadata and controls
218 lines (196 loc) · 7.95 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Threading;
using System.Timers;
namespace ScreenStealer
{
class Program
{
private static string[] config = new string[] { "image", "out.bmp", "" };
/**
* ScreenStealer Input
*
* ScreenStealer.exe type target options
*
* type: screen and window (default: screen)
* target: "console" or filepath
* options:
* if target file is HTML then we can choose "append"
* if target is a folder, options will be the "second" counter (around 20FPS)
*
*/
static async System.Threading.Tasks.Task Main(string[] args)
{
int index = 0;
foreach( string arg in args)
{
config[index] = arg;
index += 1;
}
Capture capture = new Capture();
ImageFormat format = ImageFormat.Jpeg;
string extension = ".jpeg";
string imageType = "data:image/jpeg;base64, ";
/*
* Determine the input format if we can
*/
if(config[1] != "" && config[1] != "console")
{
string pathExtension = Path.GetExtension(config[1]);
if(pathExtension != "")
{
imageType = "data:image/" + pathExtension.Substring(1) + ";base64, ";
extension = pathExtension;
switch (pathExtension)
{
case ".jpg":
format = ImageFormat.Jpeg;
break;
case ".png":
format = ImageFormat.Png;
break;
case ".bmp":
format = ImageFormat.Bmp;
break;
case ".gif":
format = ImageFormat.Gif;
break;
case ".tiff":
format = ImageFormat.Tiff;
break;
default:
format = ImageFormat.Jpeg;
break;
}
}
}
if (config[1] == "console" || config[0] == "console")
/**
* Base64 output to stdout
*
* Example for
* ScreenStealer.exe console
* ScreenStealer.exe window console
* ScreenStealer.exe screen console
*/
{
Image screen = config[0] == "window" ? capture.CaptureActiveWindow() :capture.CaptureScreen();
Console.WriteLine(imageType + ConvertImageToBase64String(screen, format));
} if (config[1].EndsWith(".html"))
/**
* HTML Output to <img></img>
*
* Example for
* ScreenStealer.exe window filename.html append
* ScreenStealer.exe window filename.html
* ScreenStealer.exe screen filename.html append
* ScreenStealer.exe screen filename.html
*/
{
Image screen = config[0] == "window" ? capture.CaptureActiveWindow() : capture.CaptureScreen();
string image = imageType + ConvertImageToBase64String(screen, format);
string startImage = "<img src=\"";
string endImage = "\" alt = \"Image\" /> ";
if(config[2] == "append")
{
using (System.IO.StreamWriter file =
new System.IO.StreamWriter(@config[1], true))
{
file.WriteLine(startImage + image + endImage);
}
} else
{
using (System.IO.StreamWriter file =
new System.IO.StreamWriter(@config[1]))
{
file.WriteLine(startImage + image + endImage);
}
}
} else if (config[1] != "")
/**
* Image file output
*
* If you provide path without extension and an integer after that,
* the application will create a series of images for that time period what you defined
*
*
* Example for
* ScreenStealer.exe window folder/ 10 //10 seconds images
* ScreenStealer.exe screen folder/ 10
* ScreenStealer.exe screen imagefile.png
* ScreenStealer.exe window imagefile.gif
* ScreenStealer.exe window imagefile.bmp
*/
{
if (config[2] != "")
{
int seconds = Int32.Parse(config[2]);
DateTime startTime = DateTime.UtcNow;
int i = 0;
if(config[0] == "window")
{
while (DateTime.UtcNow - startTime < TimeSpan.FromMinutes(seconds))
{
capture.CaptureActiveWindowToFile(config[1] + i + extension, format);
i += 1;
}
}
else
{
Console.WriteLine("Start Async Capturing");
Thread thread = new Thread(capture.StartScreenSequenceCapturingLive);
thread.Start();
//capture.StartScreenSequenceCapturingLive();
Console.WriteLine("Start " + seconds + " seconds");
while (DateTime.UtcNow - startTime < TimeSpan.FromSeconds(seconds))
{
// Waiting
}
Console.WriteLine("Stop Capturing");
//Not working properly
await capture.StopScreenSequenceCapturingLive();
Console.WriteLine("Get Captured Images");
Image[] sequence = capture.GetCapturedSequence();
foreach(Image image in sequence)
{
Console.WriteLine(config[1] + i + extension);
image.Save(config[1] + i + extension, format);
i += 1;
}
/*
Image[] sequence = capture.GetScreenSequenceArray(200);
for (int j = 0; j < sequence.Length; j++)
{
sequence[j].Save(config[1] + j + extension, format);
}*/
/*while (timer != true)
{
capture.CaptureScreenToFile(config[1] + i + extension, format);
i += 1;
}*/
}
} else
{
if(config[0] == "window")
{
capture.CaptureActiveWindowToFile(config[1], format);
} else
{
capture.CaptureScreenToFile(config[1], format);
}
}
}
}
public static string ConvertImageToBase64String(Image image, ImageFormat format)
{
using (MemoryStream ms = new MemoryStream())
{
image.Save(ms, format);
return Convert.ToBase64String(ms.ToArray());
}
}
}
}