use fs_extra::dir; 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(); dir::create_all("target/monitors", true).unwrap(); for monitor in monitors { let image = monitor.capture_image().unwrap(); image .save(format!( "target/monitors/monitor-{}.png", normalized(monitor.name()) )) .unwrap(); } println!("运行耗时: {:?}", start.elapsed()); }