diff --git a/src/macos/capture.rs b/src/macos/capture.rs index abe5bbcc..8be5b01d 100644 --- a/src/macos/capture.rs +++ b/src/macos/capture.rs @@ -35,3 +35,15 @@ pub fn capture( RgbaImage::from_raw(width as u32, height as u32, buffer) .ok_or_else(|| XCapError::new("RgbaImage::from_raw failed")) } + +pub fn capture_bytes( + cg_rect: CGRect, + list_option: CGWindowListOption, + window_id: CGWindowID, +) -> XCapResult> { + let cg_image = create_image(cg_rect, list_option, window_id, kCGWindowImageDefault) + .ok_or_else(|| XCapError::new(format!("Capture failed {} {:?}", window_id, cg_rect)))?; + + let bytes = Vec::from(cg_image.data().bytes()); + Ok(bytes) +} diff --git a/src/macos/impl_monitor.rs b/src/macos/impl_monitor.rs index eb94a82a..6636c29d 100644 --- a/src/macos/impl_monitor.rs +++ b/src/macos/impl_monitor.rs @@ -6,7 +6,7 @@ use image::RgbaImage; use crate::error::{XCapError, XCapResult}; -use super::capture::capture; +use super::capture::{capture, capture_bytes}; #[derive(Debug, Clone)] pub(crate) struct ImplMonitor { @@ -132,4 +132,12 @@ impl ImplMonitor { kCGNullWindowID, ) } + + pub fn capture_bytes(&self) -> XCapResult> { + capture_bytes( + self.cg_display.bounds(), + kCGWindowListOptionAll, + kCGNullWindowID, + ) + } } diff --git a/src/monitor.rs b/src/monitor.rs index 8d089f76..9cca907c 100644 --- a/src/monitor.rs +++ b/src/monitor.rs @@ -78,4 +78,8 @@ impl Monitor { pub fn capture_image(&self) -> XCapResult { self.impl_monitor.capture_image() } + + pub fn capture_bytes(&self) -> XCapResult> { + self.impl_monitor.capture_bytes() + } }