-
Notifications
You must be signed in to change notification settings - Fork 1
/
Capture.cs
38 lines (35 loc) · 1.03 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Drawing.Imaging;
namespace ScreenParser
{
class Capture
{
public static String imagePath = "C:\\Users\\riege\\Documents\\temp.png";
public Rectangle area;
public Capture(Rectangle rect)
{
area = rect;
makeBmp();
}
private void makeBmp()
{
int width = area.Right - area.Left;
int height = area.Bottom - area.Top;
if (height == 0 || width == 0)
{
return;
}
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb);
using (Graphics graphics = Graphics.FromImage(bmp))
{
graphics.CopyFromScreen(area.Left, area.Top, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy);
}
bmp.Save(Capture.imagePath, ImageFormat.Png);
}
}
}