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).
use std::time::Instant;
use xcap::Window;
fn main() {
let start = Instant::now();
let title = "-zsh";
let windows = Window::all().unwrap();
for window in windows {
if window.is_minimized() || window.title() != title {
continue;
}
let start2 = Instant::now();
let image = window.capture_image().unwrap();
image.save("target/iTerm.png").unwrap();
println!("ID:{} 截图耗时: {:?}", window.id(), start2.elapsed());
}
println!("运行耗时: {:?}", start.elapsed());
}
我不了解正常效率问题还是环境问题,有没有解决办法
基础环境: MacOS 12.6.8 Apple Silicon rustc 1.73.0 xcap = "0.0.5"
代码输出:
代码: