-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCapture.cs
56 lines (49 loc) · 1.49 KB
/
Capture.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
/*
* Code to capture screenshot and write to disk
*/
using System;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
using NLog;
using AutoCap.Properties;
namespace AutoCap
{
class Capture : IDisposable
{
private static Logger logger = LogManager.GetCurrentClassLogger();
private String capturePath;
private String captureFile;
public Capture()
{
capturePath = Settings.Default.CapturePath;
captureFile = Settings.Default.CaptureFile;
logger.Debug("capturePath={0}; captureFile={1};", capturePath, captureFile);
}
public void Tick(object sender, EventArgs e)
{
captureScreenToFile();
}
public void captureScreenToFile()
{
String fileName = Path.Combine(capturePath, captureFile);
try
{
Rectangle s_rect = Screen.PrimaryScreen.Bounds;
using (Bitmap bmp = new Bitmap(s_rect.Width, s_rect.Height))
{
using (Graphics gScreen = Graphics.FromImage(bmp))
gScreen.CopyFromScreen(s_rect.Location, Point.Empty, s_rect.Size);
bmp.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
}
}
catch (Exception ex)
{
logger.Error(ex, "Error writing to {0}.", fileName);
}
}
public void Dispose()
{
}
}
}