forked from mehrandvd/LumberRacer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScreenCapture.cs
33 lines (29 loc) · 923 Bytes
/
ScreenCapture.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
using System;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
namespace ScreenShotDemo
{
/// <summary>
/// Provides functions to capture the entire screen, or a particular window, and save it to a file.
/// </summary>
public class ScreenCapture : IDisposable
{
public Graphics Graphics { get; private set; }
public Image SeeHere(int width, int height)
{
var p = Cursor.Position;
Bitmap bmp = new Bitmap(width,height);
Graphics?.Dispose();
Graphics = Graphics.FromImage(bmp);
var screen = Screen.FromPoint(Cursor.Position);
Graphics.CopyFromScreen(p.X-width/2, p.Y-height/2, 0, 0, new Size(width, height));
return bmp;
}
public void Dispose()
{
Graphics.Dispose();
}
}
}