pub trait CGImageExt {
// Required methods
fn rgba_data(&self) -> Result<Vec<u8>, SCError>;
fn bgra_data(&self) -> Result<Vec<u8>, SCError>;
fn rgba_data_into(&self, dest: &mut [u8]) -> Result<usize, SCError>;
fn bgra_data_into(&self, dest: &mut [u8]) -> Result<usize, SCError>;
fn rgba_data_into_strided(
&self,
dest: &mut [u8],
dest_bytes_per_row: usize,
) -> Result<usize, SCError>;
fn bgra_data_into_strided(
&self,
dest: &mut [u8],
dest_bytes_per_row: usize,
) -> Result<usize, SCError>;
fn save(&self, path: &str, format: ImageFormat) -> Result<(), SCError>;
}Expand description
Screenshot-specific helpers implemented for the canonical CGImage type.
Import this trait to access pixel extraction helpers and multi-format file
export on images returned by SCScreenshotManager.
Required Methods§
Sourcefn bgra_data_into(&self, dest: &mut [u8]) -> Result<usize, SCError>
fn bgra_data_into(&self, dest: &mut [u8]) -> Result<usize, SCError>
Render the image’s BGRA bytes into a caller-supplied buffer.
§Errors
Returns an error if dest is too small or the render fails.
Sourcefn rgba_data_into_strided(
&self,
dest: &mut [u8],
dest_bytes_per_row: usize,
) -> Result<usize, SCError>
fn rgba_data_into_strided( &self, dest: &mut [u8], dest_bytes_per_row: usize, ) -> Result<usize, SCError>
Render the image’s RGBA bytes into a caller-supplied buffer using an
explicit row stride (dest_bytes_per_row).
Unlike rgba_data_into, which assumes
tightly-packed rows (width * 4), this accepts a caller-specified row
stride so consumers with padded/row-aligned buffers (GPU upload, wgpu)
aren’t forced into tight packing.
Returns the number of bytes spanned (height * dest_bytes_per_row).
§Errors
Returns an error if dest_bytes_per_row is smaller than width * 4,
if dest cannot hold height * dest_bytes_per_row bytes, or if the
render fails.
Sourcefn bgra_data_into_strided(
&self,
dest: &mut [u8],
dest_bytes_per_row: usize,
) -> Result<usize, SCError>
fn bgra_data_into_strided( &self, dest: &mut [u8], dest_bytes_per_row: usize, ) -> Result<usize, SCError>
Render the image’s BGRA bytes into a caller-supplied buffer using an
explicit row stride (dest_bytes_per_row).
See rgba_data_into_strided for
the row-stride semantics.
§Errors
Returns an error if dest_bytes_per_row is smaller than width * 4,
if dest cannot hold height * dest_bytes_per_row bytes, or if the
render fails.
Sourcefn save(&self, path: &str, format: ImageFormat) -> Result<(), SCError>
fn save(&self, path: &str, format: ImageFormat) -> Result<(), SCError>
Save the image to a file in the specified format.
§Errors
Returns an error if the path contains interior null bytes or the export fails.
§Examples
let image = SCScreenshotManager::capture_image(&filter, &config)?;
image.save("screenshot.png", ImageFormat::Png)?;
image.save("screenshot.jpg", ImageFormat::Jpeg(0.85))?;
image.save("screenshot.heic", ImageFormat::Heic(0.9))?;