Use github.com/kbinani/screenshot to capture a complete monitor or any desktop rectangle. The package returns an *image.RGBA; your program decides whether to encode it as PNG, JPEG, WebP, or another format and where to save it. For multiple monitors, enumerate displays with NumActiveDisplays, read each monitor’s coordinates with GetDisplayBounds, and pass those bounds to CaptureRect.
Install the package
Initialize a Go module if the project does not already have one, then install the module:
go mod init example.com/screenshot-demo
go get github.com/kbinani/screenshot
Import the screenshot package together with the standard-library packages needed for your output format and error handling. The package captures pixels; it does not create files automatically.
Capture every active monitor as a PNG
This complete program follows the package’s documented multi-display workflow. It checks file creation, PNG encoding, and file closing errors instead of discarding them.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →#1 Best Overall
- 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("capture display %d (%v): %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("create %s: %vn", name, err)
continue
}
if err := png.Encode(file, img); err != nil {
file.Close()
fmt.Printf("encode %s: %vn", name, err)
continue
}
if err := file.Close(); err != nil {
fmt.Printf("close %s: %vn", name, err)
continue
}
fmt.Printf("saved %s (%v)n", name, bounds)
}
}
Run it with go run .. Each successful capture produces a PNG in the program’s current working directory. The file name uses the display index and dimensions reported at runtime, so it does not assume a particular monitor arrangement.
Capture one monitor
When you know the display index, CaptureDisplay is the shortest route to a full-monitor image:
img, err := screenshot.CaptureDisplay(0)
if err != nil {
return err
}
file, err := os.Create("primary.png")
if err != nil {
return err
}
defer file.Close()
if err := png.Encode(file, img); err != nil {
return err
}
Index 0 is the primary display. Do not assume that its bounds are always a particular resolution; query them when you need the position or dimensions.
Capture a selected rectangle
Using x, y, width, and height
Capture accepts a rectangle expressed as four integers:
Crashes, 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 minutePC 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 & 11img, err := screenshot.Capture(100, 80, 800, 600)
if err != nil {
return err
}
The coordinates are relative to the primary-display origin. The example captures an 800-by-600 region beginning at (100, 80).
Using an image.Rectangle
CaptureRect is useful when a rectangle comes from display bounds or is assembled with the image package:
Rank #2
- 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
package main
import (
"image"
"image/png"
"os"
"github.com/kbinani/screenshot"
)
func main() {
rect := image.Rect(100, 80, 900, 680)
img, err := screenshot.CaptureRect(rect)
if err != nil {
panic(err)
}
file, err := os.Create("region.png")
if err != nil {
panic(err)
}
defer file.Close()
if err := png.Encode(file, img); err != nil {
panic(err)
}
}
Rectangle width is Max.X - Min.X and height is Max.Y - Min.Y. Validate dimensions before capturing if coordinates come from user input.
Understand monitor coordinates
The coordinate origin is the upper-left corner of the primary display, and Y increases downward. A secondary monitor positioned left of or above the primary can therefore have negative X or Y coordinates. For example, a bounds value such as (-293,-1440)-(2267,0) is valid, not an error.
Always obtain real bounds with GetDisplayBounds(i) before capturing a monitor. Hard-coding (0,0) works only for a region at the primary display’s origin and can miss monitors arranged elsewhere.
for i := 0; i < screenshot.NumActiveDisplays(); i++ {
bounds := screenshot.GetDisplayBounds(i)
fmt.Printf("display %d: min=(%d,%d), max=(%d,%d), size=%dx%dn",
i, bounds.Min.X, bounds.Min.Y,
bounds.Max.X, bounds.Max.Y,
bounds.Dx(), bounds.Dy())
}
Choose the right API
| Need | Function | Input | Result |
|---|---|---|---|
| Count monitors | NumActiveDisplays |
None | Number of active displays |
| Find a monitor’s position and size | GetDisplayBounds |
Display index | image.Rectangle |
| Capture a full monitor | CaptureDisplay |
Display index | *image.RGBA and error |
| Capture arbitrary coordinates | Capture |
X, Y, width, height | *image.RGBA and error |
| Capture a prepared rectangle | CaptureRect |
image.Rectangle |
*image.RGBA and error |
All capture methods return pixel data in memory. Encode with image/png for lossless output, or use another encoder that accepts an image.
Platform and build requirements
The project lists Windows, Darwin (macOS), Linux, FreeBSD, OpenBSD, and NetBSD support. The implementation is CGO-free except for Darwin. The API exposes ErrUnsupported for unsupported platform or architecture combinations, including Darwin builds made without CGO.
Before shipping, build for the exact operating system and architecture you will deploy. On macOS, verify that CGO is enabled and that the runtime environment permits screen capture. A successful build alone does not guarantee that the operating system will grant capture access.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Rank #3
- 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.
go env GOOS GOARCH CGO_ENABLED
go build ./...
The module publication information displayed in the package reference is dated June 24, 2025, and the reference page indicates that its default view was not showing the latest version. Pin and review the version appropriate for your project rather than relying on an unstated version.
Production considerations
Check every fallible operation
Capture calls can return errors, as can file creation, encoding, and closing. Return or log errors with the display index and rectangle so an operator can identify which monitor failed.
Control memory use
An RGBA image uses roughly four bytes per pixel before encoder buffers. A 3840-by-2160 capture is about 33 MB of raw pixel storage, and capturing several monitors simultaneously increases that total. The example captures and writes one monitor at a time, allowing the image to become eligible for collection before the next iteration.
Keep output deterministic
Use an explicit output directory, stable names, and a timestamp or job identifier when captures may overlap. If concurrent captures are introduced, ensure each goroutine writes to a different file and consider limiting concurrency to avoid unnecessary memory spikes.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsCapture timing
The package takes a snapshot of the current desktop. If another application is animating or updating content, the resulting frame can reflect that instant. For repeatable automation, arrange the desktop first and add synchronization in your own program before calling a capture function.
Troubleshooting
ErrUnsupported or an unsupported-platform error
Confirm that the target OS and architecture are among those supported by the project. On Darwin, check CGO configuration; a build without required CGO support can be rejected. Rebuild for the intended target instead of assuming a binary built on another operating system will work.
Rank #4
- 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
The wrong monitor was captured
Print NumActiveDisplays and every GetDisplayBounds result. Display indexes follow the operating system’s active-display enumeration, while physical placement is represented by the rectangle. Do not infer placement from the index.
A secondary monitor is partly missing
Inspect for negative coordinates. A monitor above or left of the primary commonly has negative Y or X values. Pass the complete rectangle returned by GetDisplayBounds to CaptureRect.
The output file is empty or missing
Check the error from os.Create, verify the process has write permission in its current directory, and close the file after encoding. Print the absolute output path when diagnosing a service or scheduled task, whose working directory may differ from an interactive shell.
The image has the wrong size
Log bounds.Dx() and bounds.Dy(). Window scaling, display configuration, and the selected rectangle determine the pixel dimensions. The package returns the captured pixel buffer; it does not resize it automatically.
macOS blocks capture
Check the operating system’s screen-recording/privacy permission for the executable that performs the capture. Permission changes may require restarting the application. This is an OS policy issue rather than a PNG-encoding problem.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
If what you need is a screenshot of a web page rather than the local desktop, a browser automation stack is unnecessary. ScreenshotNeo provides a GET endpoint that returns PNG, JPEG, WebP, or PDF. 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 identify the page verdict and billing status.
Free tools Windows power users keep installed
One-click scans. No signup required.
Basic cURL request (see the ScreenshotNeo documentation):
Best Value
- 【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.
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)
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}`);
It also supports full-page captures with lazy images, CSS-selector element captures, dark mode, device presets and custom viewports, retina scale, PDF paper and margin controls, custom CSS and JavaScript, pre-capture clicks, selector hiding, selector/delay/network-idle waits, request and resource 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 requests for up to 100 URLs, a usage API, and an OpenAPI specification. An MCP server provides take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients.
The Free plan includes 1,000 shots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is available on every plan, and annual billing provides two months free. Create a free ScreenshotNeo account to try it without a card.
API reference at a glance
NumActiveDisplays() intreports active displays.GetDisplayBounds(displayIndex int) image.Rectanglereturns a display’s desktop-relative bounds.Capture(x, y, width, height int) (*image.RGBA, error)captures an arbitrary region.CaptureRect(rect image.Rectangle) (*image.RGBA, error)captures the supplied rectangle.CaptureDisplay(displayIndex int) (*image.RGBA, error)captures one complete display.ErrUnsupportedidentifies unsupported platform or build conditions.
Frequently Asked Questions
Does kbinani/screenshot save JPEG files directly?
No. Capture functions return an *image.RGBA. Use the appropriate Go image encoder and file writer for JPEG or another format.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Can I capture a monitor located above the primary display?
Yes. Use the negative coordinates in GetDisplayBounds; the coordinate system permits negative X and Y values for displays left of or above the primary.
Is CGO required on Linux or Windows?
The project describes its implementation as CGO-free except for Darwin. Darwin builds may require CGO and can return ErrUnsupported when built without it.
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.




