using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading;
using static System.Net.Mime.MediaTypeNames;
class Program
{
private const int SM_XVIRTUALSCREEN = 76;
private const int SM_YVIRTUALSCREEN = 77;
private const int SM_CXVIRTUALSCREEN = 78;
private const int SM_CYVIRTUALSCREEN = 79;
private const int SRCCOPY = 0x00CC0020;
private const int CAPTUREBLT = 0x40000000;
[DllImport("user32.dll")]
private static extern int GetSystemMetrics(int nIndex);
[DllImport("user32.dll")]
private static extern IntPtr GetDC(int hWnd);
[DllImport("gdi32.dll")]
private static extern IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport("gdi32.dll")]
private static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);
[DllImport("gdi32.dll")]
private static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);
[DllImport("gdi32.dll")]
private static extern bool BitBlt(IntPtr hdcDest, int xDest, int yDest, int wDest, int hDest, IntPtr hdcSrc, int xSrc, int ySrc, int dwRop);
[DllImport("gdi32.dll")]
private static extern bool DeleteObject(IntPtr hObject);
[DllImport("user32.dll")]
private static extern int ReleaseDC(IntPtr hWnd, IntPtr hdc);
static void Main()
{
Console.ReadLine();
Thread.Sleep(5000);
int x = GetSystemMetrics(SM_XVIRTUALSCREEN); // left (e.g. -1024)
int y = GetSystemMetrics(SM_YVIRTUALSCREEN); // top (e.g. -34)
int cx = GetSystemMetrics(SM_CXVIRTUALSCREEN); // entire width (e.g. 2704)
int cy = GetSystemMetrics(SM_CYVIRTUALSCREEN); // entire height (e.g. 1050)
IntPtr dcScreen = GetDC((int)IntPtr.Zero);
IntPtr dcTarget = CreateCompatibleDC(dcScreen);
IntPtr bmpTarget = CreateCompatibleBitmap(dcScreen, cx, cy);
IntPtr oldBmp = SelectObject(dcTarget, bmpTarget);
BitBlt(dcTarget, 0, 0, cx, cy, dcScreen, x, y, SRCCOPY | CAPTUREBLT);
SelectObject(dcTarget, oldBmp);
// Save the screenshot as an image file
using (Bitmap screenshot = System.Drawing.Image.FromHbitmap(bmpTarget))
{
screenshot.Save("D:/screenshot.png", System.Drawing.Imaging.ImageFormat.Png);
}
// Cleanup
DeleteObject(bmpTarget);
DeleteObject(oldBmp);
DeleteObject(dcTarget);
ReleaseDC(IntPtr.Zero, dcScreen);
}
}
Take Screenshot of Fullscreen Game
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.