Crates.io | xcap |
lib.rs | xcap |
version | |
source | src |
created_at | 2024-01-21 05:59:18.168459 |
updated_at | 2024-12-11 15:45:07.282235 |
description | 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). |
homepage | https://github.com/nashaofu/xcap |
repository | https://github.com/nashaofu/xcap.git |
max_upload_size | |
id | 1107377 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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).
Feature | Linux(X11) | Linux(Wayland) | MacOS | Windows |
---|---|---|---|---|
Screen Capture | ✅ | ⛔ | ✅ | ✅ |
Window Capture | ✅ | ⛔ | ✅ | ✅ |
Screen Recording | 🛠️ | 🛠️ | 🛠️ | 🛠️ |
Window Recording | 🛠️ | 🛠️ | 🛠️ | 🛠️ |
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());
}
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());
}
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
This project is licensed under the Apache License. See the LICENSE file for details.