Skip to main content

Screenshot

Struct Screenshot 

Source
pub struct Screenshot { /* private fields */ }
Expand description

A captured screenshot backed by raw RGBA8 pixel data.

Pixels are stored in row-major order; each pixel is four consecutive bytes [R, G, B, A] with values in 0..=255.

Implementations§

Source§

impl Screenshot

Source

pub fn from_rgba(width: u32, height: u32, data: Vec<u8>) -> Screenshot

Create a screenshot from raw RGBA8 pixel data.

§Panics

Panics if data.len() != width * height * 4.

Source

pub fn from_rgb(width: u32, height: u32, data: &[u8]) -> Screenshot

Create a screenshot from raw RGB8 pixel data, promoting to RGBA8 with full opacity (alpha = 255).

§Panics

Panics if data.len() != width * height * 3.

Source

pub fn width(&self) -> u32

Width of the screenshot in pixels.

Source

pub fn height(&self) -> u32

Height of the screenshot in pixels.

Source

pub fn data(&self) -> &[u8]

Raw RGBA8 pixel data (row-major, 4 bytes per pixel).

Source

pub fn into_data(self) -> Vec<u8>

Consume the screenshot and return the underlying RGBA8 pixel buffer.

Source

pub fn encode_png(&self) -> Result<Vec<u8>, EncodeError>

Encode the screenshot as a PNG image.

Source

pub fn encode_ppm(&self) -> Vec<u8>

Encode the screenshot as a PPM (Portable Pixmap, P6 binary) image.

The alpha channel is discarded; only RGB values are written.

Source

pub fn encode_pgm(&self) -> Vec<u8>

Encode the screenshot as a PGM (Portable Graymap, P5 binary) image.

Each pixel is converted to grayscale using the ITU-R BT.601 luminance coefficients: Y = 0.299·R + 0.587·G + 0.114·B.

Source

pub fn encode(&self, format: ImageFormat) -> Result<Vec<u8>, EncodeError>

Encode the screenshot in the given ImageFormat.

Source

pub fn save<P>(&self, path: P) -> Result<(), SaveError>
where P: AsRef<Path>,

Save the screenshot to path.

The image format is inferred from the file extension (.png, .ppm, .pgm). When the extension is absent or unrecognised, PNG is used.

Source

pub fn save_as<P>(&self, path: P, format: ImageFormat) -> Result<(), SaveError>
where P: AsRef<Path>,

Save the screenshot to path in the explicitly chosen format.

Trait Implementations§

Source§

impl Clone for Screenshot

Source§

fn clone(&self) -> Screenshot

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Screenshot

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,