To take a screenshot in C#, create a Bitmap, obtain a Graphics object for that bitmap, and call Graphics.CopyFromScreen with the screen rectangle’s upper-left coordinates, a destination point of (0, 0), and the rectangle’s size. Save or process the bitmap before disposing it. The method copies pixels from a visible Windows desktop rectangle; it is not a general-purpose hidden-window or cross-platform capture API.
What Graphics.CopyFromScreen does
Microsoft describes Graphics.CopyFromScreen as performing “a bit-block transfer of color data, corresponding to a rectangle of pixels, from the screen to the drawing surface of the Graphics.” In practical terms, the method reads a rectangular area of the desktop and draws those pixels onto an existing Graphics surface.
The call has four pieces of information:
- Source location: the screen’s upper-left point, such as
sourceXandsourceY. - Destination location: where the copied pixels begin on the destination surface, commonly
(0, 0). - Block size: the width and height to copy.
- Copy operation: an optional
CopyPixelOperationvalue controlling how source and destination colors are combined.
There are overloads that accept Point and Size objects as well as integer coordinates. The simplest overload uses the normal source-copy operation.
Requirements and platform scope
Graphics.CopyFromScreen belongs to System.Drawing and is documented for Windows desktop targets, including Windows versions listed from Windows 3.0 through Windows 11, with applicability entries for .NET Framework and .NET Standard. Treat that documentation as a Windows-desktop scope, not a promise of identical behavior on Linux, macOS, browser runtimes, or every server session.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minute#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
For a modern project, target a Windows desktop framework and enable Windows targeting in the project file when required by your SDK. A Windows Forms or WPF application is the usual host, although the capture code itself can live in a reusable class. The screen rectangle must describe pixels that are actually available to the desktop session.
Capture and save a rectangular region
This complete example captures a 1,280-by-720 region beginning at screen coordinate (0, 0), writes it to a PNG file, and disposes all GDI+ resources deterministically.
using System;
using System.Drawing;
using System.Drawing.Imaging;
public static class ScreenCapture
{
public static void Main()
{
int sourceX = 0;
int sourceY = 0;
int width = 1280;
int height = 720;
string outputPath = "desktop-capture.png";
var captureRectangle = new Rectangle(sourceX, sourceY, width, height);
using (var bitmap = new Bitmap(
captureRectangle.Width,
captureRectangle.Height,
PixelFormat.Format32bppArgb))
using (Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.CopyFromScreen(
captureRectangle.Left,
captureRectangle.Top,
0,
0,
captureRectangle.Size);
bitmap.Save(outputPath, ImageFormat.Png);
}
Console.WriteLine($"Saved {outputPath}");
}
}
The bitmap dimensions match the requested block. Because the destination point is (0, 0), the screen’s top-left pixel is drawn into the bitmap’s top-left pixel. The output path and image format are application choices: use ImageFormat.Jpeg for a smaller photographic file, ImageFormat.Webp only when your image stack supports it, or another encoder appropriate to your project.
Use a Point and Size overload
The same operation can be expressed with the geometry types used by the API:
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePoint source = new Point(100, 80);
Point destination = new Point(0, 0);
Size size = new Size(800, 600);
using var bitmap = new Bitmap(size.Width, size.Height);
using var graphics = Graphics.FromImage(bitmap);
graphics.CopyFromScreen(source, destination, size);
bitmap.Save("region.png", ImageFormat.Png);
This form is convenient when a capture rectangle already exists as a Rectangle. Pass its Location as the source and its Size as the transfer size.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Capture a form or another known rectangle
For a Windows Forms control or form, calculate the screen position first, then copy that visible rectangle. A form’s client area and its outer window have different coordinates, so choose deliberately. Microsoft’s documented Windows Forms example invokes the method from a Paint event, uses the form location as the source, draws at (40, 40), and copies a 100 x 100 area.
private void Form1_Paint(object sender, PaintEventArgs e)
{
Point source = Location;
Point destination = new Point(40, 40);
Size size = new Size(100, 100);
e.Graphics.CopyFromScreen(source, destination, size);
}
In this example the destination is the form’s paint surface, not a file. For a saved image, use a bitmap-backed graphics surface as shown earlier. A minimized, occluded, or otherwise unavailable window should not be treated as an independent source: this API copies the desktop rectangle it is given.
Choosing coordinates, size, and destination
Source coordinates
sourceX and sourceY identify the screen pixel at the rectangle’s upper-left corner. Do not substitute the bitmap’s coordinates for the screen coordinates; the bitmap always starts at its own destination origin.
Destination coordinates
Use (0, 0) when the destination bitmap is exactly the requested size. A nonzero destination lets you place the copied block inside a larger drawing surface, provided the destination rectangle remains within that surface.
Width and height
Both dimensions must describe the region you intend to transfer and the destination capacity. Validate them before allocating a bitmap so a bad user-supplied value does not produce an allocation failure or an unexpectedly large image.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Multiple displays and negative coordinates
Define one capture rectangle explicitly. A virtual desktop can place a secondary monitor to the left or above the primary display, which means a desired region may have negative screen coordinates. The API accepts a source point; your application must determine the correct virtual-desktop rectangle and bitmap dimensions. Mixed-DPI desktops, remote sessions, protected content, and headless environments can have additional behavior that is not established by the basic API reference, so test those deployment conditions rather than assuming one universal result.
CopyPixelOperation overloads
Overloads that accept a CopyPixelOperation value allow source and destination colors to be copied or combined using the selected raster operation. The ordinary screenshot case uses CopyPixelOperation.SourceCopy:
graphics.CopyFromScreen(
sourceX,
sourceY,
0,
0,
bitmap.Size,
CopyPixelOperation.SourceCopy);
Use another operation only when you specifically need raster blending behavior. An invalid enumeration value can raise InvalidEnumArgumentException; keep the value within the documented enum.
Resource management and reliability
- Dispose every
BitmapandGraphics, preferably withusingdeclarations or statements. - Save the bitmap while it is still alive, then dispose it after the encoder has finished.
- Use a unique output name when captures can overlap; otherwise one process can overwrite an earlier file.
- Keep capture work off the UI thread if you take frequent or large images, but marshal UI-only coordinate calculations and controls according to your framework’s rules.
- Check that the destination directory exists and that the process has permission to write there.
- Do not assume a successful method return means that a remote, locked, or protected desktop contains the pixels you expect. Verify the resulting image in the deployment environment.
Troubleshooting common failures
Win32Exception during the copy
The API documentation lists Win32Exception when the operation fails. Check that the application is running in an interactive Windows desktop session, that the source rectangle is sensible, and that the destination bitmap is valid. Log the requested coordinates and dimensions so an out-of-range value is visible.
InvalidEnumArgumentException
This indicates an invalid CopyPixelOperation value. Use a defined enum member, normally SourceCopy for a screenshot, or call the overload without the enum.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Black, blank, or unexpected output
Confirm that the source point refers to the intended monitor and that the requested area is visible in the desktop session. Check whether the process is running under a service, disconnected remote session, locked workstation, or other environment where a normal interactive desktop is unavailable. The basic reference does not establish guaranteed behavior for each of those cases.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Only part of the image is captured
Compare the source rectangle size with the bitmap size and inspect the destination point. A destination other than (0, 0) can intentionally leave unused bitmap margins; an undersized bitmap cannot hold the entire transfer.
File cannot be saved
Use an absolute path while diagnosing, create the parent directory, and verify write permission. Ensure the bitmap has not been disposed before Save runs and that the selected encoder is available in the target runtime.
When CopyFromScreen is the right tool
Choose this method when you need a synchronous copy of a visible desktop rectangle in a Windows application and you are comfortable managing a bitmap. It is a direct fit for region snapshots, test evidence, simple screen recording frames, and drawing a desktop fragment into an existing Graphics surface.
Consider a different capture approach when the requirement is a specific window’s content regardless of whether it is visible, a browser page rendered independently of the user’s desktop, a cross-platform implementation, or a larger capture pipeline with scheduling and delivery. The API reference establishes the screen-region transfer, but does not provide comparative performance results for those alternatives.
Recommended Free Tools
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Or skip the browser setup
If what you actually need is a website image rather than the developer’s visible desktop, ScreenshotNeo provides a single HTTP endpoint. It accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Only clean shots are billed: bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and each response reports the result through X-Page-Verdict and X-Billed headers.
cURL:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Python:
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)
Node.js:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = Buffer.from(await res.arrayBuffer());
await import('node:fs/promises').then(fs => fs.writeFile('shot.webp', data));
See the ScreenshotNeo documentation for request options. It also offers an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. Features include full-page lazy-image capture, CSS-selector elements, device presets, retina scale, PDF controls, custom CSS and JavaScript, clicks, waits, request blocking, headers, cookies, authorization, timezone and geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed links, asynchronous webhooks, bulk capture of up to 100 URLs per call, usage reporting, and an OpenAPI specification. Parameters used by other screenshot APIs also work for easier migration.
The Free plan includes 1,000 screenshots each month with no card. Paid plans start at $5 for 3,000 shots; higher plans are Growth ($15 for 15,000), Pro ($39 for 60,000), Scale ($99 for 250,000), and Business ($249 for 1,000,000). Yearly billing gives two months free, and every feature is available on every plan. Sign up free to get the 1,000 monthly screenshots without a card.
FAQ
Does CopyFromScreen capture a hidden window?
No. It copies pixels from the screen rectangle supplied to it; the documented operation is not an independent hidden-window renderer.
Free tools Windows power users keep installed
One-click scans. No signup required.
Can I capture directly to a file?
No. Copy into a drawing surface such as a bitmap, then save that bitmap with an image encoder.
Which operation should a normal screenshot use?
Use the overload without a raster operation or specify CopyPixelOperation.SourceCopy.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

