2015-07-26 13:27:38 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
2015-07-28 09:48:27 +00:00
|
|
|
|
using System.Drawing.Imaging;
|
2015-07-25 22:10:59 +00:00
|
|
|
|
using System.Windows.Forms;
|
2015-07-26 13:27:38 +00:00
|
|
|
|
using xClient.Core.Utilities;
|
2015-07-25 22:10:59 +00:00
|
|
|
|
|
|
|
|
|
namespace xClient.Core.Helper
|
|
|
|
|
{
|
2015-07-26 14:44:03 +00:00
|
|
|
|
public static class ScreenHelper
|
2015-07-25 22:10:59 +00:00
|
|
|
|
{
|
2015-07-26 13:27:38 +00:00
|
|
|
|
private const int SRCCOPY = 0x00CC0020;
|
|
|
|
|
|
|
|
|
|
public static Bitmap CaptureScreen(int screenNumber)
|
2015-07-25 22:10:59 +00:00
|
|
|
|
{
|
2015-07-26 13:27:38 +00:00
|
|
|
|
Rectangle bounds = GetBounds(screenNumber);
|
2015-07-28 09:48:27 +00:00
|
|
|
|
Bitmap screen = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppPArgb);
|
2015-07-26 13:27:38 +00:00
|
|
|
|
|
|
|
|
|
using (Graphics g = Graphics.FromImage(screen))
|
2015-07-25 22:10:59 +00:00
|
|
|
|
{
|
2015-07-26 13:27:38 +00:00
|
|
|
|
IntPtr destDeviceContext = g.GetHdc();
|
2015-07-27 11:20:39 +00:00
|
|
|
|
IntPtr srcDeviceContext = NativeMethods.CreateDC("DISPLAY", null, null, IntPtr.Zero);
|
2015-07-26 13:27:38 +00:00
|
|
|
|
|
|
|
|
|
NativeMethods.BitBlt(destDeviceContext, 0, 0, bounds.Width, bounds.Height, srcDeviceContext, bounds.X,
|
|
|
|
|
bounds.Y, SRCCOPY);
|
|
|
|
|
|
2015-07-27 11:20:39 +00:00
|
|
|
|
NativeMethods.DeleteDC(srcDeviceContext);
|
2015-07-26 13:27:38 +00:00
|
|
|
|
g.ReleaseHdc(destDeviceContext);
|
2015-07-25 22:10:59 +00:00
|
|
|
|
}
|
2015-07-26 13:27:38 +00:00
|
|
|
|
|
|
|
|
|
return screen;
|
2015-07-25 22:10:59 +00:00
|
|
|
|
}
|
2015-07-26 08:42:53 +00:00
|
|
|
|
|
|
|
|
|
public static Rectangle GetBounds(int screenNumber)
|
|
|
|
|
{
|
|
|
|
|
return Screen.AllScreens[screenNumber].Bounds;
|
|
|
|
|
}
|
2015-07-25 22:10:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|