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

For a basic screenshot of a desktop display in Rust, XCap is a practical starting point: enumerate monitors, call capture_image(), then save the returned image. This guide uses the XCap 0.9.8 API documented in its README; crate APIs and native dependencies can change, so check the current documentation before adopting the code. XCap documents Linux, macOS, and Windows support, but Linux Wayland has limitations in some scenarios.

Choose the capture approach that fits your application

“Screenshot” can mean several different jobs. Choose a crate based on what you need to capture, not just on whether a project calls itself cross-platform.

  • One still image from a desktop monitor: start with XCap. Its documented flow is short: list monitors, capture an image, and save it.
  • A configurable capture pipeline or selectable capture targets: investigate Scap. Its documented setup includes support and permission checks, display/window target selection, and capture configuration.
  • A macOS-only integration using Apple’s ScreenCaptureKit: consider ScreenCaptureKit-rs, while checking its OS version requirements and permission flow.
  • The older screenshots crate: treat it as migration context rather than the default for new code; its README says “Move to XCap.”

These projects do not document interchangeable scopes. Before choosing, check your operating system and session type (especially X11 versus Wayland on Linux), whether you need a display, window, or region, and whether you need a single frame or an ongoing capture pipeline.

Capture a monitor and save it with XCap

The following small command-line example captures the first monitor returned by XCap and writes a PNG. It uses XCap 0.9.8’s documented monitor enumeration and capture_image() flow. Confirm the exact API against the crate version you install.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • 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.

1. Create a Rust project

cargo new rust-screenshot
cd rust-screenshot

Add XCap to Cargo.toml. This version line is tied to the 0.9.8 documentation snapshot; check the crate page for the current release before pinning or upgrading.

[dependencies]
xcap = "0.9.8"

2. Capture the first monitor

Replace src/main.rs with this version using fallible error handling rather than the unwrap() shortcuts often used in introductory examples:

use std::io;
use xcap::Monitor;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let monitors = Monitor::all()?;
    let Some(monitor) = monitors.first() else {
        return Err(io::Error::new(
            io::ErrorKind::NotFound,
            "No monitors were returned by XCap",
        )
        .into());
    };

    let image = monitor.capture_image()?;
    image.save("screenshot.png")?;
    println!("Saved screenshot.png");
    Ok(())
}

Run it from the project directory:

cargo run

If capture succeeds, the program reports the output filename and saves screenshot.png in the process’s current working directory. If the machine has more than one display, this example captures the first monitor in the returned list; it does not ask the user to choose a display.

Capture a region, window, or more than one display

XCap’s README also demonstrates region capture. Use its current examples as the reference for the region API and coordinate parameters; the minimal program above intentionally avoids guessing those signatures. A region is useful when the application should save only part of a display, but the caller must decide how the region coordinates relate to the selected monitor and handle invalid or out-of-bounds selections.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 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.

For multiple monitors, enumerate the returned monitors and capture the selected entry or each entry according to the application’s needs. Do not assume monitor ordering means “primary display”: the example simply takes the first item. Present monitor selection explicitly if users need predictable control.

If the target is specifically an application window rather than a monitor, check the crate’s documented target support and examples for your platform. Scap’s README describes display and window target enumeration as part of its more configurable pipeline; it should not be mistaken for a drop-in minimal still-image recipe.

Install the platform’s native prerequisites

A Rust crate can depend on native system libraries as well as Cargo packages. XCap’s 0.9.8 documentation lists platform-specific Linux development packages, and the list is not a universal command for every distribution or build environment.

Linux

For Debian/Ubuntu, the documented dependency set includes pkg-config, libclang-dev, XCB/XRandR, D-Bus, PipeWire, Wayland, and EGL development packages. Package names and requirements may differ by release and configuration. Use the current XCap platform instructions to choose the packages for the distribution and features you actually target rather than copying a list blindly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • 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.

Linux session type matters: XCap documents Linux X11 and Wayland, but its platform table warns that Wayland capture is limited in some special scenarios. A program that works under X11 may therefore behave differently in a Wayland session. Confirm behavior on the actual desktop/session combination you ship.

macOS

Use the crate’s current macOS instructions and test on the macOS versions your app supports. If you choose ScreenCaptureKit-rs instead, its documentation states a deployment floor of macOS 13.0 for the crate, while the documented single-frame screenshot APIs are for macOS 14.0 and later.

Windows

XCap documents Windows 8.1 and later. Check the current crate requirements and compile/test on the Windows versions you intend to support; a successful build on one version is not proof that every capture path behaves identically elsewhere.

When to use Scap or ScreenCaptureKit-rs

Scap: an explicitly configured capture pipeline

Scap’s README shows a sequence that checks scap::is_supported(), checks or requests permission with has_permission() and request_permission(), obtains display and window targets, configures capture options, and starts capture. It identifies ScreenCaptureKit on macOS, Windows.Graphics.Capture on Windows, and PipeWire on Linux as underlying APIs. This makes it worth investigating when target selection, permissions, and a configured pipeline are central requirements. Follow the project README for the full API rather than treating the sequence as a minimal one-shot screenshot snippet.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • 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

ScreenCaptureKit-rs: macOS-specific requirements

ScreenCaptureKit-rs documents single-frame screenshot APIs for macOS 14.0+, despite the crate’s macOS 13.0 deployment floor. Screen recording permission must be granted by the user in System Settings → Privacy & Security → Screen Recording. After enabling the relevant app or binary, restart it before testing capture again. The crate is a platform-specific choice, not a cross-platform substitute for XCap.

screenshots: useful older examples, but not the new-project default

The screenshots README shows Screen::all(), capture(), and capture_area(...) followed by saving the image. It also directs readers to move to XCap, so use it to understand older code or migration context rather than as the first choice for a new implementation. Its README lists Linux packages including libxcb, libxrandr, and dbus.

Common failures and what to check

  • Compilation fails while building a native dependency: install the development packages for your OS and distribution, including the Linux packages required by the XCap instructions. Re-run Cargo after installing them; a Rust dependency declaration alone does not install system headers or libraries.
  • No monitor is returned: handle the empty list as the example does, then check the runtime environment and platform support. A headless process or restricted session may not expose a capturable display.
  • Capture works in one Linux session but not another: identify whether the session is X11 or Wayland and check XCap’s documented Wayland qualifications. Test on the target session rather than inferring support from a different desktop setup.
  • macOS capture remains unavailable after enabling access: verify Screen Recording permission in System Settings, ensure the permission is granted to the app/binary actually performing capture, and restart that app.
  • The saved file is not where expected: the sample uses a relative path, so the destination is the process’s working directory. Supply an explicit output path if the application needs a stable location, and handle file-save errors.
  • The wrong display is captured: the sample chooses the first enumerated monitor, not necessarily the display the user considers primary. Add explicit selection using the current XCap monitor information and validate the chosen index.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Reliability, performance, and cost considerations

The cited project documentation describes APIs and platform support, not comparative performance benchmarks. Do not assume a capture rate, latency, or memory footprint from the crate name or a successful single capture. Measure with your intended resolution, monitor count, OS/session type, and capture frequency.

For production code, propagate capture and image-save failures, provide a useful message to the user, and avoid assuming a GUI permission prompt will appear in every environment. If capturing repeatedly, decide deliberately how often to capture and how to manage image buffers and files. Verify native prerequisites in CI or packaging documentation for each supported OS rather than relying only on a developer machine.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 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

The Rust code above captures a local desktop display. If what you need is a screenshot of a public website rather than the computer’s screen, ScreenshotNeo is a website screenshot API and MCP server from Yorker Media; it is not a replacement for local display capture. One GET request returns an image or PDF. See the ScreenshotNeo API documentation.

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

Before the shot, it accepts cookie/consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, with response headers indicating the page verdict and billing status. Its MCP server lets AI agents use screenshot tools. The free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots.

Sign up free for 1,000 screenshots a month, with no card required.

Frequently Asked Questions

Does the XCap example capture the mouse cursor?

The cited XCap README material does not establish cursor-capture behavior. Check the current crate documentation for a supported cursor option before relying on it.

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

Can I use this approach to screenshot a webpage without opening a desktop browser?

XCap captures a local display. For a website URL rendered as an image or PDF, use a website screenshot service such as ScreenshotNeo rather than treating desktop capture as URL rendering.

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.