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

Use github.com/kbinani/screenshot to capture a complete monitor or any desktop rectangle, then encode the returned *image.RGBA yourself. The usual workflow is: install the module, inspect display bounds, call CaptureDisplay, CaptureRect, or Capture, and write the image with Go’s PNG, JPEG, or another encoder.

Install the package

Initialize a Go module if your project does not have one, then add the dependency:

go mod init example.com/screen-capture
go get github.com/kbinani/screenshot

Import the package as screenshot. It returns an *image.RGBA; file format and destination are your application’s responsibility. The project is MIT-licensed and its repository lists Windows, Darwin (macOS), Linux, FreeBSD, OpenBSD, and NetBSD support.

Capture every active monitor and save PNG files

This complete program follows the package’s documented multi-display sequence while checking file and encoding errors:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
package main

import (
    "fmt"
    "image/png"
    "os"

    "github.com/kbinani/screenshot"
)

func main() {
    displays := screenshot.NumActiveDisplays()
    if displays == 0 {
        fmt.Println("no active displays")
        return
    }

    for i := 0; i < displays; i++ {
        bounds := screenshot.GetDisplayBounds(i)
        img, err := screenshot.CaptureRect(bounds)
        if err != nil {
            fmt.Printf("display %d (%v): capture failed: %vn", i, bounds, err)
            continue
        }

        name := fmt.Sprintf("display-%d-%dx%d.png", i, bounds.Dx(), bounds.Dy())
        file, err := os.Create(name)
        if err != nil {
            fmt.Printf("display %d: create %s: %vn", i, name, err)
            continue
        }

        encodeErr := png.Encode(file, img)
        closeErr := file.Close()
        if encodeErr != nil {
            fmt.Printf("display %d: encode: %vn", i, encodeErr)
            continue
        }
        if closeErr != nil {
            fmt.Printf("display %d: close: %vn", i, closeErr)
            continue
        }
        fmt.Printf("saved %s (%v)n", name, bounds)
    }
}

Run it with go run .. Each successful iteration creates a PNG in the process’s current directory. Obtain the bounds at runtime: monitor arrangements, resolutions, scaling, and positions vary between machines.

Choose the capture function for the area you need

Function Arguments Use it when
CaptureDisplay Display index You want one complete monitor.
CaptureRect image.Rectangle You already have a rectangle, commonly from GetDisplayBounds.
Capture x, y, width, height int You need an arbitrary desktop region.

All capture calls return an image and an error. A one-monitor capture can therefore be as small as:

img, err := screenshot.CaptureDisplay(0)
if err != nil {
    return err
}

To capture a 640-by-480 region beginning at desktop coordinate (100, 100):

img, err := screenshot.Capture(100, 100, 640, 480)
if err != nil {
    return err
}

For a rectangle, import image and pass its coordinates:

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.
region := image.Rect(100, 100, 740, 580)
img, err := screenshot.CaptureRect(region)
if err != nil {
    return err
}

Understand coordinates on multiple monitors

The coordinate origin is the upper-left corner of the primary display, and Y increases downward. Display 0 is the primary display. Other monitors can have negative X or Y coordinates when they sit to the left of, or above, the primary screen. Never assume every monitor begins at (0, 0).

Inspect the actual layout before constructing a region:

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
for i := 0; i < screenshot.NumActiveDisplays(); i++ {
    fmt.Printf("display %d: %v, size %dx%dn",
        i,
        screenshot.GetDisplayBounds(i),
        screenshot.GetDisplayBounds(i).Dx(),
        screenshot.GetDisplayBounds(i).Dy(),
    )
}

The documented sample output contains rectangles such as (-293,-1440)-(2267,0) and (-1373,-1812)-(-293,108). Those numbers describe one particular arrangement, not defaults; use your own runtime values.

Write JPEG or another image format

The capture result implements Go’s image interfaces. PNG is lossless and needs no quality setting. For JPEG, use image/jpeg and choose a quality:

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

import (
    "image/jpeg"
    "os"

    "github.com/kbinani/screenshot"
)

func saveJPEG(path string, display int) error {
    img, err := screenshot.CaptureDisplay(display)
    if err != nil {
        return err
    }
    f, err := os.Create(path)
    if err != nil {
        return err
    }
    defer f.Close()
    return jpeg.Encode(f, img, &jpeg.Options{Quality: 90})
}

WebP and other formats require an encoder package that your application imports; screenshot itself does not select or write those formats.

Build and platform requirements

  • Windows, Linux, FreeBSD, OpenBSD, NetBSD: the repository describes implementations that do not require CGO.
  • Darwin (macOS): the implementation uses CGO. A build without the required CGO setup can fail or return ErrUnsupported.
  • Unsupported combinations: the API exposes ErrUnsupported for platform or architecture combinations it cannot handle.

Check the target operating system, architecture, and CGO settings in the environment where the binary will actually run. A successful build on one platform does not establish support for another. The package reference displayed a latest module publication date of June 24, 2025; pin and verify the version appropriate for your project rather than relying on an unstated version.

Production considerations

Always close output files

Check os.Create, encoder, and Close errors. Closing only after a successful encode prevents descriptor leaks in repeated captures. For many files, process one image at a time instead of retaining every *image.RGBA in a slice.

Expect changing display topology

Laptops can add or remove docks and virtual displays while your process runs. Query NumActiveDisplays and bounds when starting a capture batch, and handle an index or rectangle that becomes invalid by reporting the error rather than writing a misleading file.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.

Control output size deliberately

Full-resolution RGBA images consume memory proportional to width times height and four bytes per pixel before encoding. Large or high-density monitors therefore create larger temporary allocations and files. Capture only the required rectangle, or encode to JPEG when a smaller lossy file is acceptable.

Keep capture and encoding errors separate

A successful screen read does not guarantee that the destination is writable, and a writable destination does not guarantee that the capture succeeded. Logging the display index, rectangle, and operation that failed makes automated jobs diagnosable.

Troubleshooting

ErrUnsupported or an unsupported-platform error

Confirm that the target OS and architecture are among those supported by the project. On macOS, verify that CGO is enabled and that the native build prerequisites are present. Rebuild for the intended target rather than assuming a binary built elsewhere will work.

The screenshot is from the wrong area

Print GetDisplayBounds for every active display. Negative coordinates are valid in a multi-monitor layout; hard-coding a rectangle beginning at zero can select the wrong monitor or an empty area.

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.

The program writes no file

Check the current working directory and handle os.Create errors. A relative filename is resolved against the directory from which the program is launched, not necessarily the directory containing the source.

An image is truncated or corrupt

Do not exit before the encoder returns, and close the file after encoding. Check both errors. For concurrent capture jobs, give each output a unique path so writers cannot overwrite one another.

Rank #4
Sale
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient

There are no active displays

NumActiveDisplays can be zero in a headless service or disconnected-session environment. Treat that as a normal no-capture result and use a virtual display or an environment designed for desktop capture if your deployment requires pixels.

Or skip the browser setup

If what you need is a screenshot of a public web page rather than the local desktop, ScreenshotNeo provides a GET endpoint and an MCP server for AI agents. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status.

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

One request returns PNG, JPEG, WebP, or PDF. See the ScreenshotNeo API documentation for all options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
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)
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}`);
require('fs').writeFileSync('shot.webp', Buffer.from(await res.arrayBuffer()));

ScreenshotNeo also supports full-page lazy-image loading, CSS-selector element capture, dark mode, device presets and custom viewports, retina scale, PDF paper and page-range controls, custom CSS and JavaScript, pre-capture clicks, selector hiding, selector/delay/network-idle waits, request blocking, custom headers/cookies/user agents/Authorization, timezone and geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification. Parameter names used by other screenshot APIs also work, easing migration. Its MCP tools are take_screenshot, get_page_info, and capture_pdf.

Plan Allowance Price
Free 1,000 shots/month $0, no card
Starter 3,000 shots $5
Growth 15,000 shots $15
Pro 60,000 shots $39
Scale 250,000 shots $99
Business 1,000,000 shots $249

Yearly billing provides two months free, and every feature is included on every plan. Create a free ScreenshotNeo account to get 1,000 screenshots a month without a card.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

FAQ

Does the package return PNG bytes?

No. It returns *image.RGBA; your code chooses PNG, JPEG, or another encoder and writes the bytes.

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

Can I capture a monitor identified by its operating-system name?

The documented API addresses displays by zero-based index. Use NumActiveDisplays and GetDisplayBounds to inspect that index-based layout.

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

Are negative coordinates an error?

No. They represent monitors positioned left of or above the primary display in the documented desktop coordinate system.

Is CGO required everywhere?

No. The repository describes CGO-free implementations except for Darwin; macOS builds need the appropriate CGO configuration.

Frequently Asked Questions

Does the package return PNG bytes?

No. It returns *image.RGBA; your code chooses PNG, JPEG, or another encoder and writes the bytes.

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

Can I capture a monitor identified by its operating-system name?

The documented API addresses displays by zero-based index. Use NumActiveDisplays and GetDisplayBounds to inspect that index-based layout.

Are negative coordinates an error?

No. They represent monitors positioned left of or above the primary display in the documented desktop coordinate system.

Is CGO required everywhere?

No. The repository describes CGO-free implementations except for Darwin; macOS builds need the appropriate CGO configuration.

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.

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