| 22 | |
| 23 | #[cfg(windows)] |
| 24 | fn record(i: usize) { |
| 25 | use std::time::Duration; |
| 26 | |
| 27 | use scrap::{Frame, TraitPixelBuffer}; |
| 28 | |
| 29 | for d in Display::all().unwrap() { |
| 30 | println!("{:?} {} {}", d.origin(), d.width(), d.height()); |
| 31 | } |
| 32 | |
| 33 | let display = get_display(i); |
| 34 | let (w, h) = (display.width(), display.height()); |
| 35 | |
| 36 | { |
| 37 | let mut capture_mag = CapturerMag::new(display.origin(), display.width(), display.height()) |
| 38 | .expect("Couldn't begin capture."); |
| 39 | let wnd_cls = ""; |
| 40 | let wnd_name = "RustDeskPrivacyWindow"; |
| 41 | if false == capture_mag.exclude(wnd_cls, wnd_name).unwrap() { |
| 42 | println!("No window found for cls {} name {}", wnd_cls, wnd_name); |
| 43 | } else { |
| 44 | println!("Filter window for cls {} name {}", wnd_cls, wnd_name); |
| 45 | } |
| 46 | |
| 47 | let frame = capture_mag.frame(Duration::from_millis(0)).unwrap(); |
| 48 | let Frame::PixelBuffer(frame) = frame else { |
| 49 | return; |
| 50 | }; |
| 51 | let frame = frame.data(); |
| 52 | println!("Capture data len: {}, Saving...", frame.len()); |
| 53 | |
| 54 | let mut bitflipped = Vec::with_capacity(w * h * 4); |
| 55 | let stride = frame.len() / h; |
| 56 | |
| 57 | for y in 0..h { |
| 58 | for x in 0..w { |
| 59 | let i = stride * y + 4 * x; |
| 60 | bitflipped.extend_from_slice(&[frame[i + 2], frame[i + 1], frame[i], 255]); |
| 61 | } |
| 62 | } |
| 63 | // Save the image. |
| 64 | let name = format!("capture_mag_{}_1.png", i); |
| 65 | repng::encode( |
| 66 | File::create(name.clone()).unwrap(), |
| 67 | w as u32, |
| 68 | h as u32, |
| 69 | &bitflipped, |
| 70 | ) |
| 71 | .unwrap(); |
| 72 | println!("Image saved to `{}`.", name); |
| 73 | } |
| 74 | |
| 75 | { |
| 76 | let mut capture_mag = CapturerMag::new(display.origin(), display.width(), display.height()) |
| 77 | .expect("Couldn't begin capture."); |
| 78 | let wnd_cls = ""; |
| 79 | let wnd_title = "RustDeskPrivacyWindow"; |
| 80 | if false == capture_mag.exclude(wnd_cls, wnd_title).unwrap() { |
| 81 | println!("No window found for cls {} title {}", wnd_cls, wnd_title); |