#screen-capture #screen #capture #window #image #monitor

xcap

XCap is a cross-platform screen capture library written in Rust. It supports Linux (X11, Wayland), MacOS, and Windows. XCap supports screenshot and video recording (to be implemented).

9 releases

0.0.9 Apr 28, 2024
0.0.8 Mar 30, 2024
0.0.4 Feb 20, 2024
0.0.3 Jan 30, 2024

#86 in GUI

Download history 13/week @ 2024-01-22 50/week @ 2024-01-29 60/week @ 2024-02-05 43/week @ 2024-02-12 261/week @ 2024-02-19 171/week @ 2024-02-26 99/week @ 2024-03-04 335/week @ 2024-03-11 195/week @ 2024-03-18 406/week @ 2024-03-25 151/week @ 2024-04-01 153/week @ 2024-04-08 161/week @ 2024-04-15 290/week @ 2024-04-22 719/week @ 2024-04-29 224/week @ 2024-05-06

1,438 downloads per month
Used in spoilers

Apache-2.0

80KB
2K SLoC

XCap

English | 简体中文

XCap is a cross-platform screen capture library written in Rust. It supports Linux (X11, Wayland), MacOS, and Windows. XCap supports screenshot and video recording (to be implemented).

Features

  • Cross-platform: Supports Linux (X11, Wayland), MacOS, and Windows.
  • Supports multiple screenshot modes: Can take screenshots of the screen and windows.
  • Supports video recording: Supports recording of the screen or window (to be implemented).

Implementation Status

Feature Linux(X11) Linux(Wayland) MacOS Windows
Screen Capture
Window Capture
Screen Recording 🛠️ 🛠️ 🛠️ 🛠️
Window Recording 🛠️ 🛠️ 🛠️ 🛠️
  • ✅: Feature available
  • ⛔: Feature available, but not fully supported in some special scenarios
  • 🛠️: To be developed

Examples

  • Screen Capture
use std::time::Instant;
use xcap::Monitor;

fn normalized(filename: &str) -> String {
    filename
        .replace("|", "")
        .replace("\\", "")
        .replace(":", "")
        .replace("/", "")
}

fn main() {
    let start = Instant::now();
    let monitors = Monitor::all().unwrap();

    for monitor in monitors {
        let image = monitor.capture_image().unwrap();

        image
            .save(format!("target/monitor-{}.png", normalized(monitor.name())))
            .unwrap();
    }

    println!("运行耗时: {:?}", start.elapsed());
}
  • Window Capture
use std::time::Instant;
use xcap::Window;

fn normalized(filename: &str) -> String {
    filename
        .replace("|", "")
        .replace("\\", "")
        .replace(":", "")
        .replace("/", "")
}

fn main() {
    let start = Instant::now();
    let windows = Window::all().unwrap();

    let mut i = 0;

    for window in windows {
        // 最小化的窗口不能截屏
        if window.is_minimized() {
            continue;
        }

        println!(
            "Window: {:?} {:?} {:?}",
            window.title(),
            (window.x(), window.y(), window.width(), window.height()),
            (window.is_minimized(), window.is_maximized())
        );

        let image = window.capture_image().unwrap();
        image
            .save(format!(
                "target/window-{}-{}.png",
                i,
                normalized(window.title())
            ))
            .unwrap();

        i += 1;
    }

    println!("运行耗时: {:?}", start.elapsed());
}

Linux System Requirements

On Linux, you need to install libxcb, libxrandr, and dbus.

Debian/Ubuntu:

apt-get install libxcb1 libxrandr2 libdbus-1-3

Alpine:

apk add libxcb libxrandr dbus

ArchLinux:

pacman -S libxcb libxrandr dbus

License

This project is licensed under the Apache License. See the LICENSE file for details.

Dependencies

~12–52MB
~673K SLoC