-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScreenCapture.cs
29 lines (25 loc) · 974 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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
namespace BrickadiaAutoPainter {
class ScreenCapture {
public static Bitmap CaptureWindow(IntPtr window) {
Windows.RECT rect = new Windows.RECT();
Windows.GetWindowRect(window, ref rect);
Rectangle rectangle = new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
Bitmap bitmap = new Bitmap(rectangle.Width, rectangle.Height);
using Graphics graphics = Graphics.FromImage(bitmap);
graphics.CopyFromScreen(new Point(rectangle.Left, rectangle.Top), Point.Empty, rectangle.Size);
return bitmap;
}
public static Bitmap CropBitmap(Bitmap bitmap, Rectangle cropping) {
Bitmap newBitmap = new Bitmap(cropping.Width, cropping.Height);
using (Graphics graphics = Graphics.FromImage(newBitmap)) {
graphics.DrawImage(bitmap, -cropping.X, -cropping.Y);
return newBitmap;
}
}
}
}