pub struct SCScreenshotManager;Expand description
Manager for capturing single screenshots
Available on macOS 14.0+. Provides a simpler API than SCStream for one-time captures.
§Examples
use screencapturekit::screenshot_manager::SCScreenshotManager;
use screencapturekit::stream::{content_filter::SCContentFilter, configuration::SCStreamConfiguration};
use screencapturekit::shareable_content::SCShareableContent;
let content = SCShareableContent::get()?;
let display = &content.displays()[0];
let filter = SCContentFilter::create().with_display(display).with_excluding_windows(&[]).build();
let config = SCStreamConfiguration::new()
.with_width(1920)
.with_height(1080);
let image = SCScreenshotManager::capture_image(&filter, &config)?;
println!("Captured screenshot: {}x{}", image.width(), image.height());Implementations§
Source§impl SCScreenshotManager
impl SCScreenshotManager
Sourcepub fn capture_image(
content_filter: &SCContentFilter,
configuration: &SCStreamConfiguration,
) -> Result<CGImage, SCError>
pub fn capture_image( content_filter: &SCContentFilter, configuration: &SCStreamConfiguration, ) -> Result<CGImage, SCError>
Sourcepub fn capture_sample_buffer(
content_filter: &SCContentFilter,
configuration: &SCStreamConfiguration,
) -> Result<CMSampleBuffer, SCError>
pub fn capture_sample_buffer( content_filter: &SCContentFilter, configuration: &SCStreamConfiguration, ) -> Result<CMSampleBuffer, SCError>
Sourcepub fn capture_image_in_rect(rect: CGRect) -> Result<CGImage, SCError>
pub fn capture_image_in_rect(rect: CGRect) -> Result<CGImage, SCError>
Capture a screenshot of a specific screen region (macOS 15.2+)
This method captures the content within the specified rectangle, which can span multiple displays.
§Arguments
rect- The rectangle to capture, in screen coordinates (points)
§Errors
Returns an error if:
- The system is not macOS 15.2+
- Screen recording permission is not granted
- The capture fails for any reason
§Examples
use screencapturekit::screenshot_manager::SCScreenshotManager;
use screencapturekit::cg::CGRect;
fn example() -> Result<(), screencapturekit::utils::error::SCError> {
let rect = CGRect::new(0.0, 0.0, 1920.0, 1080.0);
let image = SCScreenshotManager::capture_image_in_rect(rect)?;
Ok(())
}Sourcepub fn capture_screenshot(
content_filter: &SCContentFilter,
configuration: &SCScreenshotConfiguration,
) -> Result<SCScreenshotOutput, SCError>
pub fn capture_screenshot( content_filter: &SCContentFilter, configuration: &SCScreenshotConfiguration, ) -> Result<SCScreenshotOutput, SCError>
Capture a screenshot with advanced configuration (macOS 26.0+)
This method uses the new SCScreenshotConfiguration for more control
over the screenshot output, including HDR support and file saving.
§Arguments
content_filter- The content filter specifying what to captureconfiguration- The screenshot configuration
§Errors
Returns an error if the capture fails
§Examples
use screencapturekit::screenshot_manager::{SCScreenshotManager, SCScreenshotConfiguration, SCScreenshotDynamicRange};
use screencapturekit::stream::content_filter::SCContentFilter;
use screencapturekit::shareable_content::SCShareableContent;
fn example() -> Option<()> {
let content = SCShareableContent::get().ok()?;
let displays = content.displays();
let display = displays.first()?;
let filter = SCContentFilter::create().with_display(display).with_excluding_windows(&[]).build();
let config = SCScreenshotConfiguration::new()
.with_width(1920)
.with_height(1080)
.with_dynamic_range(SCScreenshotDynamicRange::BothSDRAndHDR);
let output = SCScreenshotManager::capture_screenshot(&filter, &config).ok()?;
if let Some(sdr) = output.sdr_image() {
println!("SDR image: {}x{}", sdr.width(), sdr.height());
}
Some(())
}Sourcepub fn capture_screenshot_in_rect(
rect: CGRect,
configuration: &SCScreenshotConfiguration,
) -> Result<SCScreenshotOutput, SCError>
pub fn capture_screenshot_in_rect( rect: CGRect, configuration: &SCScreenshotConfiguration, ) -> Result<SCScreenshotOutput, SCError>
Auto Trait Implementations§
impl Freeze for SCScreenshotManager
impl RefUnwindSafe for SCScreenshotManager
impl Send for SCScreenshotManager
impl Sync for SCScreenshotManager
impl Unpin for SCScreenshotManager
impl UnsafeUnpin for SCScreenshotManager
impl UnwindSafe for SCScreenshotManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more