Quasar/Client/Core/Helper/ScreenHelper.cs

39 lines
1.2 KiB
C#
Raw Normal View History

2015-07-26 13:27:38 +00:00
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
2015-07-26 13:27:38 +00:00
using xClient.Core.Utilities;
namespace xClient.Core.Helper
{
2015-07-26 14:44:03 +00:00
public static class ScreenHelper
{
2015-07-26 13:27:38 +00:00
private const int SRCCOPY = 0x00CC0020;
public static Bitmap CaptureScreen(int screenNumber)
{
2015-07-26 13:27:38 +00:00
Rectangle bounds = GetBounds(screenNumber);
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-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-26 13:27:38 +00:00
return screen;
}
2015-07-26 08:42:53 +00:00
public static Rectangle GetBounds(int screenNumber)
{
return Screen.AllScreens[screenNumber].Bounds;
}
}
}