-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
1,946 additions
and
631 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,34 @@ | ||
[package] | ||
name = "screenshots" | ||
version = "0.8.7" | ||
name = "xcap" | ||
version = "0.0.1" | ||
edition = "2021" | ||
description = "A cross-platform screen capturer library" | ||
description = "A cross-platform screen capture library" | ||
license = "Apache-2.0" | ||
documentation = "https://docs.rs/screenshots" | ||
homepage = "https://github.com/nashaofu/screenshots-rs" | ||
repository = "https://github.com/nashaofu/screenshots-rs.git" | ||
keywords = ["screenshots", "screenshot", "screen", "capture"] | ||
documentation = "https://docs.rs/xcap" | ||
homepage = "https://github.com/nashaofu/xcap" | ||
repository = "https://github.com/nashaofu/xcap.git" | ||
keywords = ["screen", "monitor", "window", "capture", "image"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
anyhow = "1.0" | ||
display-info = "0.4" | ||
image = "0.24" | ||
percent-encoding = "2.3" | ||
thiserror = "1.0" | ||
|
||
[target.'cfg(target_os = "macos")'.dependencies] | ||
core-graphics = "0.22" | ||
core-foundation = "0.9" | ||
core-graphics = "0.23" | ||
|
||
[target.'cfg(target_os = "windows")'.dependencies] | ||
fxhash = "0.2" | ||
widestring = "1.0" | ||
windows = { version = "0.51", features = [ | ||
windows = { version = "0.52", features = [ | ||
"Win32_Foundation", | ||
"Win32_Graphics_Gdi", | ||
"Win32_Graphics_Dwm", | ||
"Win32_UI_WindowsAndMessaging", | ||
"Win32_Storage_Xps", | ||
] } | ||
|
||
[target.'cfg(target_os="linux")'.dependencies] | ||
percent-encoding = "2.3" | ||
xcb = { version = "1.3", features = ["randr"] } | ||
dbus = { version = "0.9", features = ["vendored"] } | ||
libwayshot = "0.2" | ||
xcb = "1.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::time::Instant; | ||
use xcap::Monitor; | ||
|
||
fn main() { | ||
let start = Instant::now(); | ||
let monitors = Monitor::all().unwrap(); | ||
println!("Monitor::all() 运行耗时: {:?}", start.elapsed()); | ||
|
||
for monitor in monitors { | ||
println!( | ||
"Monitor: {} {} {:?} {:?}", | ||
monitor.id(), | ||
monitor.name(), | ||
(monitor.x(), monitor.y(), monitor.width(), monitor.height()), | ||
( | ||
monitor.rotation(), | ||
monitor.scale_factor(), | ||
monitor.frequency(), | ||
monitor.is_primary() | ||
) | ||
); | ||
} | ||
|
||
let monitor = Monitor::from_point(100, 100).unwrap(); | ||
|
||
println!("Monitor::from_point(): {}", monitor.name()); | ||
println!( | ||
"Monitor::from_point(100, 100) 运行耗时: {:?}", | ||
start.elapsed() | ||
); | ||
|
||
println!("运行耗时: {:?}", start.elapsed()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
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()); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use std::time::Instant; | ||
use xcap::Window; | ||
|
||
fn main() { | ||
let start = Instant::now(); | ||
let windows = Window::all().unwrap(); | ||
println!("Window::all() 运行耗时: {:?}", start.elapsed()); | ||
|
||
for window in windows { | ||
println!( | ||
"Window: {} {} {} {:?} {:?} {:?}", | ||
window.id(), | ||
window.title(), | ||
window.app_name(), | ||
window.current_monitor().name(), | ||
(window.x(), window.y(), window.width(), window.height()), | ||
(window.is_minimized(), window.is_maximized()) | ||
); | ||
} | ||
|
||
println!("运行耗时: {:?}", start.elapsed()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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()); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.