SCScreenshotManager

Struct SCScreenshotManager 

Source
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

Source

pub fn capture_image( content_filter: &SCContentFilter, configuration: &SCStreamConfiguration, ) -> Result<CGImage, SCError>

Capture a single screenshot as a CGImage

§Errors

Returns an error if:

  • The system is not macOS 14.0+
  • Screen recording permission is not granted
  • The capture fails for any reason
§Panics

Panics if the internal mutex is poisoned.

Source

pub fn capture_sample_buffer( content_filter: &SCContentFilter, configuration: &SCStreamConfiguration, ) -> Result<CMSampleBuffer, SCError>

Capture a single screenshot as a CMSampleBuffer

Returns the sample buffer for advanced processing.

§Errors

Returns an error if:

  • The system is not macOS 14.0+
  • Screen recording permission is not granted
  • The capture fails for any reason
§Panics

Panics if the internal mutex is poisoned.

Source

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(())
}
Source

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 capture
  • configuration - 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(())
}
Source

pub fn capture_screenshot_in_rect( rect: CGRect, configuration: &SCScreenshotConfiguration, ) -> Result<SCScreenshotOutput, SCError>

Capture a screenshot of a specific region with advanced configuration (macOS 26.0+)

§Arguments
  • rect - The rectangle to capture, in screen coordinates (points)
  • configuration - The screenshot configuration
§Errors

Returns an error if the capture fails

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.