The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Use Xcap’s monitor, region, or window APIs, then save the returned image as PNG, JPEG, or another format supported by the image crate. The core pattern is straightforward: add xcap = "0.9.8", enumerate a capture target, call capture_image(), and write the resulting image to disk. Xcap 0.9.8 uses Rust edition 2024, is licensed under Apache-2.0, and supports Linux X11, macOS, and Windows. Linux Wayland works in some scenarios but is not fully supported everywhere.
What Xcap captures
Xcap is a cross-platform screen-capture library written in Rust. It exposes separate APIs for monitors and windows, plus bounded rectangle capture within a monitor. Each capture returns an image buffer that can be saved through the image API’s save method.
| Capture goal | API entry point | How you choose the target | Typical failure |
|---|---|---|---|
| Entire monitor | Monitor::capture_image() |
Enumerate monitors or select the primary monitor | No monitor or platform capture error |
| Rectangle | Monitor::capture_region(x, y, width, height) |
Coordinates relative to the selected monitor | InvalidCaptureRegion when the rectangle exceeds bounds |
| Window | Window::capture_image() |
Window title, application name, focus, or ID | Window is minimized or unavailable |
Window recording is a separate capability and is still marked as work to be developed; this guide covers still screenshots.
Install Xcap 0.9.8
Create a binary crate and add the currently documented release:
#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.
[dependencies]
xcap = "0.9.8"
Xcap uses the image crate for the returned image type. The normal image-format encoders are available through Xcap’s default setup; if your project disables defaults, enable the documented image feature as appropriate for your dependency configuration.
Linux native packages
On Debian or Ubuntu, install the development libraries before compiling:
apt-get install pkg-config libclang-dev libxcb1-dev libxrandr-dev
libdbus-1-dev libpipewire-0.3-dev libwayland-dev libegl-dev
Alpine and Arch require equivalent packages for pkg-config, Clang, XCB/XRandR, D-Bus, PipeWire, Wayland, and EGL. These are compile-time and native-integration prerequisites, not special capture hardware.
Capture every monitor as PNG
Monitor::all() returns the monitors visible to the platform backend. Iterate through them, capture each one, and save a numbered file:
use std::error::Error;
use xcap::Monitor;
fn main() -> Result<(), Box<dyn Error>> {
let monitors = Monitor::all()?;
for (index, monitor) in monitors.into_iter().enumerate() {
let image = monitor.capture_image()?;
image.save(format!("monitor-{index}.png"))?;
}
Ok(())
}
Run it with cargo run --release. The files are written to the process’s current working directory. The returned image is an RGBA image, and the extension passed to save selects the encoder.
Capture only the primary monitor
Monitor ordering is not a portable way to identify the main display. Use the monitor metadata instead:
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.
use std::error::Error;
use xcap::Monitor;
fn main() -> Result<(), Box<dyn Error>> {
let monitor = Monitor::all()?
.into_iter()
.find(|m| m.is_primary().unwrap_or(false))
.ok_or("no primary monitor found")?;
let image = monitor.capture_image()?;
image.save("primary.png")?;
Ok(())
}
If no monitor reports itself as primary, present a clear error or offer a monitor picker based on the metadata exposed by Xcap.
Capture a region of a monitor
Region coordinates are relative to the selected monitor, not to a virtual desktop that spans all displays. This example captures the top-left 400 by 300 pixels of the primary monitor:
use std::error::Error;
use xcap::Monitor;
fn main() -> Result<(), Box<dyn Error>> {
let monitor = Monitor::all()?
.into_iter()
.find(|m| m.is_primary().unwrap_or(false))
.ok_or("no primary monitor found")?;
let image = monitor.capture_region(0, 0, 400, 300)?;
image.save("region.png")?;
Ok(())
}
Xcap validates the rectangle. If x + width or y + height goes beyond the monitor dimensions, the call returns an InvalidCaptureRegion error. Validate user-supplied values before calling it:
let x = 100;
let y = 80;
let width = 800;
let height = 600;
if x < 0 || y < 0 || width == 0 || height == 0
|| x as u32 + width > monitor.width()?
|| y as u32 + height > monitor.height()? {
return Err("capture rectangle is outside monitor bounds".into());
}
let image = monitor.capture_region(x, y, width, height)?;
Use the exact integer types required by the version of the API in your build; the important rule is that the rectangle must be non-negative, non-zero, and wholly inside the selected monitor.
Capture a window
Enumerate windows, filter by metadata, skip minimized entries, and save the selected window:
use std::error::Error;
use xcap::Window;
fn main() -> Result<(), Box<dyn Error>> {
let window = Window::all()?
.into_iter()
.find(|w| {
!w.is_minimized().unwrap_or(true)
&& w.title().map(|t| t.contains("Editor")).unwrap_or(false)
})
.ok_or("window not found")?;
let image = window.capture_image()?;
image.save("editor.png")?;
Ok(())
}
The window API exposes identifiers and state useful for a picker: id, pid, app_name, title, current_monitor, coordinates, z-order, dimensions, is_minimized, is_maximized, is_focused, and capture_image.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →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.
Focused-window utility
For a utility that follows the active window, repeatedly enumerate Window::all(), retain the entry whose is_focused() is true, and capture it. Treat a missing focused window as a normal retry condition rather than unwrapping an optional value.
Choose the right capture mode
Full monitor
Use this for desktop documentation, multi-application workflows, or a display-level snapshot. It is the least sensitive to window metadata but includes everything visible on that display.
Region
Use a region for a toolbar, chart, or fixed coordinate area. It avoids unrelated desktop content, but your UI must account for monitor size, scaling, and coordinate validation.
Window
Use a window when the application can move or resize and you do not want the desktop around it. Matching by title can break when titles change; a picker based on application name, process ID, or window ID is more robust. Minimized windows should be skipped in the documented workflow.
Recommended Free Tools
Output formats and file handling
image.save("shot.png") infers PNG from the extension. You can choose another supported extension such as JPEG or WebP when the corresponding encoder is available in your image setup. PNG preserves lossless pixels and transparency; JPEG is smaller for photographic content but loses detail and does not preserve alpha. Check and handle the result from both capture and save so permission or filesystem errors are not hidden.
Platform support and permissions
- Windows: screen and window capture are marked as supported.
- macOS: screen and window capture are marked as supported. If capture fails, review the operating system’s Screen Recording privacy setting for the terminal or application running your binary. The exact prompt and menu sequence can vary by macOS release.
- Linux X11: screen and window capture are marked as supported. Install the native development packages before building.
- Linux Wayland: support exists but is not fully supported in some special scenarios. Test with the compositor and desktop environment used by your application; a result that works under X11 is not proof that every Wayland session will work.
Common errors and fixes
“Could not find” a monitor or window
Check that the session exposes a monitor, that the window still exists, and that your filter is not too strict. Log titles and application names before choosing one. For focused capture, retry when no focused entry is returned.
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
InvalidCaptureRegion
The rectangle extends outside the selected monitor. Read the monitor dimensions, reject negative or zero sizes, and verify both right and bottom edges before calling capture_region.
Window capture returns an error for a minimized window
Skip entries where is_minimized() is true or report that the user must restore the window. Do not assume a minimized surface contains current pixels.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Build fails on Linux
Install the Debian/Ubuntu packages shown above (or their Alpine/Arch equivalents), then run cargo clean and rebuild. Confirm that pkg-config and the native headers are visible to the same environment running Cargo.
Capture is blank or denied on macOS
Open the relevant Screen Recording privacy controls, grant access to the application that actually performs the capture, restart it if the operating system requests a restart, and try again.
Wayland behaves differently from X11
Reproduce the issue on the target compositor, test a full-monitor capture before a window or region capture, and provide a fallback or an explicit unsupported-session message when your deployment requires consistent behavior.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Reliability, performance, and security practices
No authoritative benchmark establishes a universal capture time for Xcap. Capture cost depends on display resolution, scaling, backend, compositor, and filesystem speed. For a responsive application:
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 problemsBest 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.
- Run capture and disk I/O off the UI thread.
- Reuse a selected monitor or window instead of enumerating repeatedly when your workflow permits it.
- Throttle repeated screenshots and avoid writing every frame when you need only occasional snapshots.
- Write to a temporary file and rename it after a successful save if another process reads the output.
- Do not log authorization headers, window content, or sensitive screenshots in diagnostic output.
- Re-enumerate after display hot-plugging, window closure, sleep, or resolution changes; stale metadata can become invalid.
Or skip the browser setup
If your actual goal is a website image rather than a local desktop or application window, ScreenshotNeo provides a one-request website screenshot API and an MCP server for AI agents. It removes cookie/consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers. Its MCP tools include take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients.
See the ScreenshotNeo API documentation for all options. A minimal call is:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
The equivalent Python and Node.js requests are:
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)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
ScreenshotNeo supports full-page and element capture, device presets, custom viewports, retina scale, PDFs, custom CSS and JavaScript, clicks, waits, request blocking, headers, cookies, user agents, timezone and geolocation, transparent backgrounds, resizing, TTL caching, signed links, asynchronous webhooks, bulk capture, usage reporting, and an OpenAPI specification. Every feature is on every plan. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. Create a free ScreenshotNeo account.
FAQ
Is Xcap a command-line screenshot tool?
No. It is a Rust Cargo library, so you call its APIs from your program and decide how to expose commands, hotkeys, or a service around them.
Can Xcap capture a monitor and a window in the same program?
Yes. Enumerate monitors and windows independently, then call the corresponding capture method for each target.
Does Xcap automatically capture videos?
This guide concerns still images. The project’s implementation table marks window recording as work to be developed, so do not treat screenshot support as a finished recording pipeline.
Frequently Asked Questions
Can I capture a monitor that is not the primary display?
Yes. Use `Monitor::all()`, inspect each monitor’s metadata, and call `capture_image()` on the one you select.
Where are the generated files saved?
Unless you provide an absolute path, `image.save(…)` writes relative to the process’s current working directory.
What license does xcap use?
The currently documented xcap 0.9.8 package is licensed under Apache-2.0.
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.

