Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To take a screenshot with Graphics.CopyFromScreen in C#, choose the screen rectangle, create a bitmap with the same dimensions, create a Graphics object for that bitmap, and copy the pixels from the screen into it. The captured bitmap can then be saved as PNG, JPEG, WebP (when supported by your imaging library), or another format.

Microsoft defines 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.” It copies visible screen pixels; it is not a separate hidden-window or webpage renderer.

What Graphics.CopyFromScreen does

The method transfers a rectangular block from a source point on the desktop to a destination point on a Graphics surface. In the usual save-to-file workflow, the destination surface belongs to a bitmap.

  • Source point: the screen’s upper-left coordinate for the capture.
  • Destination point: where that block begins on the destination graphics surface, commonly (0, 0).
  • Size: the width and height of the rectangle to transfer.

There are overloads that accept Point values or separate integer coordinates. Other overloads accept a CopyPixelOperation, which controls how source and destination colors are copied or combined.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Dell Optiplex 3060 Desktop Computer | Intel i5-8500 (3.2) | 32GB DDR4 RAM | 1TB SSD Solid State | Built in WiFi | Bluetooth | Windows 11 Professional | Home or Office PC (Renewed)
  • [INTEL POWERED CONTENT] - Built with a 8th Generation Hexa-Core Intel i5 and 32GB of DDR4 RAM; Modern, Windows 11 ready, with 4K support, Executive multitasking, media streaming and smooth, multi-tab web browsing; Perfect as an all-purpose multimedia computer; built for content creators; Plenty of RAM and Mass storage for photo and video editing powered by Intel HD 630
  • [LATEST WIRELESS TECH] - This Dell Desktop Computer easily connects to the internet through the Built In WiFi / Bluetooth
  • [SOLID STATE STORAGE] - This Dell Computer setup comes with an ultra-fast 1TB Solid State Drive (SSD); Setup as the primary boot device; Boot and load programs with lightning speed ; Additional expansion available
  • [BUY & OWN WITH CONFIDENCE] - From the world's largest Microsoft Authorized Refurbisher; Quality Guarantee and Free Tech Support; Award-winning Customer Service; | Support Sustainable Business
  • [MODERN HI-SPEED PORTS] - USB 3.0 (x4) | USB 2.0 (x4) | DisplayPort (x1) | HDMI Port (x1) | Audio Combo Jack (x1) | Audio Out (x1) | RJ-45 Ethernet (x1) | Internal SATA (x3)

Prerequisites and platform scope

This is a Windows desktop API. Microsoft’s API reference lists it for Windows Desktop versions 3.0 through 11, with applicability entries for .NET Framework and .NET Standard. Select a Windows-capable target framework and test on the desktop session where the capture will run; do not treat it as a universal cross-platform screenshot API.

For modern .NET projects, a Windows Forms or WPF application is the normal host. A console program can also call the method when it runs in an interactive Windows desktop session and references the appropriate System.Drawing assemblies.

Capture a region and save it as PNG

The following complete example captures a 640-by-480 region beginning at screen coordinate (100, 100) and saves it as a PNG. The bitmap and graphics objects are disposed automatically.

using System.Drawing;
using System.Drawing.Imaging;

int sourceX = 100;
int sourceY = 100;
int width = 640;
int height = 480;
string outputPath = @"C:Tempregion.png";

using (var bitmap = new Bitmap(width, height))
using (var graphics = Graphics.FromImage(bitmap))
{
    graphics.CopyFromScreen(
        sourceX,
        sourceY,
        0,
        0,
        bitmap.Size,
        CopyPixelOperation.SourceCopy);

    bitmap.Save(outputPath, ImageFormat.Png);
}

CopyPixelOperation.SourceCopy requests a direct source copy. The overload without that final argument is simpler and is suitable when the default operation meets your needs.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Using Point values

using System.Drawing;

Point source = new Point(100, 100);
Point destination = Point.Empty;
Size size = new Size(640, 480);

graphics.CopyFromScreen(source, destination, size);

The destination point is relative to the bitmap-backed graphics surface, not another screen coordinate system. For a bitmap created at the capture size, (0, 0) places the first captured pixel at the bitmap’s first pixel.

Rank #2
Dell Optiplex 7050 SFF Desktop PC Intel i7-7700 4-Cores 3.60GHz 32GB DDR4 1TB SSD WiFi BT HDMI Duel Monitor Support Windows 11 Pro Excellent Condition(Renewed)
  • Model: Dell OptiPlex 7050 Small Form Factor (SFF)
  • Processor: Intel Core i7-7700 3.60 GHz
  • Memory: 32GB DDR4 Ram
  • Storage: 1TB Solid State Drive (SSD) Fast Boot + Storage
  • Operating System: Windows 11 Pro (64-bit)

Capture the entire primary display

In Windows Forms, Screen.PrimaryScreen.Bounds supplies the primary display’s bounds. Use its location as the source point and its size for the bitmap.

using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;

var bounds = Screen.PrimaryScreen.Bounds;
string outputPath = @"C:Tempprimary-display.png";

using (var bitmap = new Bitmap(bounds.Width, bounds.Height))
using (var graphics = Graphics.FromImage(bitmap))
{
    graphics.CopyFromScreen(
        bounds.X,
        bounds.Y,
        0,
        0,
        bounds.Size,
        CopyPixelOperation.SourceCopy);

    bitmap.Save(outputPath, ImageFormat.Png);
}

Compile this example in a Windows desktop project with Windows Forms enabled. The exact display bounds should be selected by your application rather than assumed to start at coordinate zero.

Capture a selected rectangle

A reusable method keeps rectangle validation and resource management in one place.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
using System;
using System.Drawing;
using System.Drawing.Imaging;

static void SaveScreenRectangle(Rectangle capture, string path)
{
    if (capture.Width <= 0 || capture.Height <= 0)
        throw new ArgumentException("Capture rectangle must have positive dimensions.", nameof(capture));

    using (var bitmap = new Bitmap(capture.Width, capture.Height))
    using (var graphics = Graphics.FromImage(bitmap))
    {
        graphics.CopyFromScreen(
            capture.X,
            capture.Y,
            0,
            0,
            capture.Size,
            CopyPixelOperation.SourceCopy);

        bitmap.Save(path, ImageFormat.Png);
    }
}

SaveScreenRectangle(new Rectangle(100, 100, 800, 600), @"C:Tempcapture.png");

Use PNG for lossless UI text and diagrams. JPEG produces smaller files for photographic content but introduces compression artifacts. The path, file extension, and image format are application choices; ensure the destination directory exists and the process has write permission.

Use the call in a Windows Forms Paint event

Microsoft’s example calls CopyFromScreen from a form’s Paint event, using the form location as the source, destination (40, 40), and a 100 x 100 region.

Rank #3
HP 2025 22" FHD All-in-One Desktop Computer • The New Version for Everyday Use • Latest 13th Gen Intel Quad-Core CPU • 8GB DDR5 • 128GB Storage • HDMI • Type-C • Wi-Fi • HD Webcam • Win11 Pro • Black
  • 【Processor】 Latest 13th Gen Intel N100 Processor (4 cores, up to 3.4GHz, 6MB cache, 4 threads) with integrated Intel UHD Graphics, delivering efficient performance for everyday computing.
  • 【Premium RAM and Storage】 Equipped with up to 32GB DDR5 RAM, ensuring lightning-fast performance, seamless multitasking, and superior responsiveness for heavy workloads. Up to 640GB total storage (128GB UFS + 512GB HP External Flash Drive) offers the perfect combination of high-speed internal storage for quick boot-ups and app launches, plus massive external storage for large files, media, and backups.
  • 【Ports】 1x USB Type-C (5Gbps, data transfer only), 2x USB Type-A (Hi-Speed), 1x USB Type-A (5Gbps), 1x headphone/microphone combo (3.5mm), 1x RJ-45 Ethernet, 1x HDMI-out, and built-in WiFi 6 & Bluetooth 5.3 for seamless connectivity.
  • 【Display and Built-in Features】 21.5" Full HD (1920 x 1080) display, offering sharp visuals with an anti-glare coating for comfortable viewing. Dual stereo speakers provide clear and immersive audio, while a built-in HD webcam with a privacy shutter ensures secure video conferencing and online meetings.
  • 【Operating System】 Pre-installed with Windows 11 Pro (64-bit), providing enhanced security, business-grade features, and remote desktop support, making it an excellent choice for professionals and power users.
private void Form1_Paint(object sender, PaintEventArgs e)
{
    e.Graphics.CopyFromScreen(
        Location,
        new Point(40, 40),
        new Size(100, 100));
}

This draws the copied pixels directly into the form. If you need a file, use a bitmap-backed graphics surface as shown earlier. Avoid capturing repeatedly in Paint unless you intentionally need a live view; repaint frequency can make disk writes and allocations expensive.

Coordinates, displays, and sizing

Choose one rectangle

Define the source rectangle before allocating the bitmap. Its width and height must match the bitmap dimensions you intend to fill. A mismatch can crop the result or leave portions of the destination unchanged.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Multiple monitors

For a desktop spanning several displays, obtain the desired display or virtual-desktop rectangle from your Windows UI framework, then pass that rectangle’s X, Y, Width, and Height. Displays can have negative coordinates when one monitor is positioned left or above another. Do not hard-code an assumption that every monitor begins at (0, 0).

DPI and remote sessions

The API reference establishes rectangular screen transfer, but it does not define every mixed-DPI, DPI-virtualization, protected-content, headless-session, or remote-desktop behavior. If exact physical-pixel dimensions matter, test the application with the DPI-awareness configuration and session types you support.

CopyPixelOperation choices

The overload with CopyPixelOperation lets you request a raster operation. SourceCopy is the straightforward choice for a screenshot because it replaces destination pixels with source pixels. Other enum values can blend or combine colors, but an invalid value can raise InvalidEnumArgumentException. Keep the operation explicit when reviewing or maintaining capture code.

Rank #4
Sale
Dell OptiPlex 7050 Desktop Computer PC, Intel Core i5 7500 3.40GHz 16GB DDR4 RAM, 512GB SSD, Built-in Wi-Fi, Bluetooth, Windows 11 Pro, 4K Support HD Graphics 630 (Renewed)
  • 【AN INDUSTRY LEADER】- As a Microsoft Authorized Refurbisher, we pride ourselves on producing quality remanufactured PCs. Every machine is handled with care, and our experts are dedicated to giving them a new life. We are committed to reducing e-waste, and it is our goal to ensure each machine we process can satisfy our customers needs.
  • 【PROCESSOR】- Intel Core i5 7500 (6MB Cache, 3.4GHz up to 3.8GHz Turbo Boost). TPM 2.0 is recommended for Windows 11, yet this PC only has TPM 1.2. This PC may not support all security features and newest updates.
  • 【RAM & STORAGE】- 16GB DDR4 RAM, 512GB SSD, Preloaded with Windows 11 Pro 64-bit.
  • 【CONNECTIVITY】- 2x Display Port 1.2; 1x HDMI 1.4; 1x USB 3.0 Type C; 5x USB-A 3.0; 4x USB-A 2.0
  • 【BUILT IN WIFI & BLUETOOTH】- Built-in Intel 7260 featuring the latest 802.11ac Wi-Fi for enhanced wireless performance and integrated Bluetooth for seamless device connectivity.

Performance and reliability practices

  • Allocate the bitmap once when taking a series of captures at a fixed size, rather than allocating on every timer tick.
  • Save asynchronously or queue file writes if capture happens on a UI thread; encoding and disk I/O can make the interface unresponsive.
  • Use a bounded capture size and avoid retaining many large bitmaps, which can exhaust process memory.
  • Dispose every Graphics and Bitmap promptly with using statements.
  • Check the return path and catch exceptions around the capture and save operations so a transient desktop failure does not terminate the application.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting

Win32Exception during CopyFromScreen

Microsoft documents Win32Exception when the operation fails. Verify that the process is running in an available interactive Windows desktop session, that the rectangle is valid, and that the destination graphics surface was created successfully. Log the exception’s message and native error information for diagnosis.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

InvalidEnumArgumentException

This indicates an invalid CopyPixelOperation value. Use a defined enum member such as SourceCopy, or call the overload that does not take the operation.

Black, blank, or incomplete output

Confirm that the source coordinates identify the intended visible desktop area and that the bitmap dimensions equal the capture size. Check whether the program is running without an interactive desktop, through a remote session, or against content that the operating system does not expose as ordinary screen pixels. Those cases require environment-specific testing.

The file is not created

Check that the directory exists, the path is not locked by another process, and the account has write permission. Select an image encoder matching the intended format instead of relying only on a filename extension.

The screenshot is the wrong size

Compare the rectangle passed to CopyFromScreen with the bitmap’s Width and Height. Also check display scaling and the DPI-awareness configuration of the Windows application.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Dell Windows 11 Desktop Computer OptiPlex 5060 | Intel Core i5-8500 Six Core (4.3GHz Turbo) | 16GB DDR4 RAM | 500GB SSD Solid State + 1TB HDD | WiFi + Bluetooth | Home or Office PC (Renewed)
  • Connectivity: Includes WiFi, Bluetooth, and LAN for wireless and wired connections
  • Memory: Features 16GB DDR4 RAM for smooth multitasking and performance
  • Storage: Combines 500GB SSD and 1TB HDD for ample storage space
  • Graphics: Integrated Intel UHD Graphics 630 for crisp visuals and video playback
  • Design: Sleek desktop tower with black color and slim profile for modern look

When CopyFromScreen is the wrong tool

Use this API when you need visible desktop pixels from a rectangular region. Consider another approach when you need the contents of a specific window without regard to what is visible, a browser page rendered independently of the desktop, or a cross-platform capture framework. The official reference establishes the screen-region transfer, not detailed performance comparisons with those alternatives.

Or skip the browser setup

If your real goal is a website screenshot rather than a Windows desktop region, ScreenshotNeo makes one HTTP request and returns a PNG, JPEG, WebP, or PDF. Its capture pipeline accepts cookie and consent banners, then removes more than 60 known consent platforms, newsletter popups, and chat widgets before the shot. Each cleanup step can be disabled.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo documentation for request options. Failed bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed; response headers identify the page verdict and billing result. ScreenshotNeo also provides an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 screenshots. Create a free ScreenshotNeo account.

Frequently Asked Questions

Can CopyFromScreen capture a hidden window?

No. It copies pixels from a visible screen rectangle to a Graphics surface; it is not documented as an independent hidden-window renderer.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Which image format should I use?

PNG is generally appropriate for lossless interface captures. JPEG is useful when smaller photographic files matter, at the cost of compression artifacts.

Does the method work on macOS or Linux?

The cited API documentation lists Windows Desktop applicability. Treat it as a Windows-focused API and choose a platform-specific alternative for other operating systems.

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.