Struct screenshots::Image

source ·
pub struct Image { /* private fields */ }

Implementations§

source§

impl Image

source

pub fn new(width: u32, height: u32, rgba: Vec<u8>) -> Self

source

pub fn from_bgra( bgra: Vec<u8>, width: u32, height: u32, bytes_per_row: usize ) -> Self

source

pub fn width(&self) -> u32

source

pub fn height(&self) -> u32

source

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

source

pub fn to_png<T: Into<Option<Compression>>>( &self, compression: T ) -> Result<Vec<u8>, EncodingError>

Examples found in repository?
examples/screenshots.rs (line 11)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
fn main() {
    let start = Instant::now();
    let screens = Screen::all().unwrap();

    for screen in screens {
        println!("capturer {screen:?}");
        let mut image = screen.capture().unwrap();
        let mut buffer = image.to_png(None).unwrap();
        let mut compressed_buffer = image.to_png(Compression::Best).unwrap();
        fs::write(format!("target/{}.png", screen.display_info.id), buffer).unwrap();
        fs::write(
            format!("target/{}-compressed.png", screen.display_info.id),
            compressed_buffer,
        )
        .unwrap();

        image = screen.capture_area(300, 300, 300, 300).unwrap();
        buffer = image.to_png(Compression::Fast).unwrap();
        compressed_buffer = image.to_png(Compression::Best).unwrap();

        fs::write(format!("target/{}-2.png", screen.display_info.id), buffer).unwrap();

        fs::write(
            format!("target/{}-2-compressed.png", screen.display_info.id),
            compressed_buffer,
        )
        .unwrap();
    }

    let screen = Screen::from_point(100, 100).unwrap();
    println!("capturer {screen:?}");

    let image = screen.capture_area(300, 300, 300, 300).unwrap();
    let buffer = image.to_png(Compression::Default).unwrap();
    let compressed_buffer = image.to_png(Compression::Best).unwrap();

    fs::write("target/capture_display_with_point.png", buffer).unwrap();
    fs::write("target/capture_display_with_point.png", compressed_buffer).unwrap();
    println!("运行耗时: {:?}", start.elapsed());
}

Trait Implementations§

source§

impl From<Image> for Vec<u8>

source§

fn from(image: Image) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl RefUnwindSafe for Image

§

impl Send for Image

§

impl Sync for Image

§

impl Unpin for Image

§

impl UnwindSafe for Image

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.