This repository has been archived by the owner on Oct 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathfeature_screenshot.rs
43 lines (42 loc) · 2.18 KB
/
feature_screenshot.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use crabgrab::{feature::bitmap::VideoFrameBitmap as _, prelude::*};
use futures::executor::block_on;
fn main() {
block_on(async {
let token = match CaptureStream::test_access(false) {
Some(token) => token,
None => CaptureStream::request_access(false).await.expect("Expected capture access")
};
let filter = CapturableContentFilter::NORMAL_WINDOWS;
let content = CapturableContent::new(filter).await.unwrap();
let window = content.windows().filter(|window| {
let app_identifier = window.application().identifier();
window.title().len() != 0 && app_identifier.to_lowercase().contains("firefox")
}).next();
match window {
Some(window) => {
println!("screenshotting window: {}", window.title());
let config = CaptureConfig::with_window(window, CaptureStream::supported_pixel_formats()[0]).unwrap();
match crabgrab::feature::screenshot::take_screenshot(token, config).await {
Ok(frame) => {
println!("Got frame: {}", frame.frame_id());
match frame.get_bitmap() {
Ok(bitmap) => {
match bitmap {
crabgrab::feature::bitmap::FrameBitmap::BgraUnorm8x4(_) => println!("format: BgraUnorm8x4"),
crabgrab::feature::bitmap::FrameBitmap::ArgbUnormPacked2101010(_) => println!("format: RgbaUnormPacked1010102"),
crabgrab::feature::bitmap::FrameBitmap::RgbaF16x4(_) => println!("format: RgbaF16x4"),
crabgrab::feature::bitmap::FrameBitmap::YCbCr(_) => println!("format: YCbCr"),
}
},
Err(e) => {
println!("Bitmap error: {:?}", e);
}
}
},
Err(_) => println!("screenshot failed!"),
}
},
None => { println!("Failed to find window"); }
}
});
}