-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathProgram.cs
More file actions
53 lines (49 loc) · 1.75 KB
/
Program.cs
File metadata and controls
53 lines (49 loc) · 1.75 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
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;
namespace SharpScreenshot
{
class Program
{
static void Main(string[] args)
{
string fileName;
if (args.Length == 1)
{
fileName = args[0];
}
else
{
fileName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".jpeg";
}
try
{
// Determine the size of the "virtual screen", which includes all monitors.
int screenLeft = SystemInformation.VirtualScreen.Left;
int screenTop = SystemInformation.VirtualScreen.Top;
int screenWidth = SystemInformation.VirtualScreen.Width;
int screenHeight = SystemInformation.VirtualScreen.Height;
// Create a bitmap of the appropriate size to receive the screenshot.
using (Bitmap bmp = new Bitmap(screenWidth, screenHeight))
{
// Draw the screenshot into our bitmap.
using (Graphics g = Graphics.FromImage(bmp))
{
g.CopyFromScreen(screenLeft, screenTop, 0, 0, bmp.Size);
}
// Do something with the Bitmap here, like save it to a file:
bmp.Save(fileName, ImageFormat.Jpeg);
}
Console.WriteLine("[+] Saved screenshot to:");
Console.WriteLine("\t{0}", fileName);
}
catch (Exception ex)
{
Console.WriteLine("[X] Error: {0}", ex);
}
}
}
}