Files
Quasar/Client/Core/Helper/ScreenHelper.cs
T
2015-07-27 13:20:39 +02:00

38 lines
1.1 KiB
C#

using System;
using System.Drawing;
using System.Windows.Forms;
using xClient.Core.Utilities;
namespace xClient.Core.Helper
{
public static class ScreenHelper
{
private const int SRCCOPY = 0x00CC0020;
public static Bitmap CaptureScreen(int screenNumber)
{
Rectangle bounds = GetBounds(screenNumber);
Bitmap screen = new Bitmap(bounds.Width, bounds.Height);
using (Graphics g = Graphics.FromImage(screen))
{
IntPtr destDeviceContext = g.GetHdc();
IntPtr srcDeviceContext = NativeMethods.CreateDC("DISPLAY", null, null, IntPtr.Zero);
NativeMethods.BitBlt(destDeviceContext, 0, 0, bounds.Width, bounds.Height, srcDeviceContext, bounds.X,
bounds.Y, SRCCOPY);
NativeMethods.DeleteDC(srcDeviceContext);
g.ReleaseHdc(destDeviceContext);
}
return screen;
}
public static Rectangle GetBounds(int screenNumber)
{
return Screen.AllScreens[screenNumber].Bounds;
}
}
}