Struct screenshots::Screen

source ·
pub struct Screen {
    pub display_info: DisplayInfo,
}

Fields§

§display_info: DisplayInfo

Implementations§

source§

impl Screen

source

pub fn new(display_info: &DisplayInfo) -> Self

source

pub fn all() -> Result<Vec<Screen>>

Examples found in repository?
examples/screenshots.rs (line 7)
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
44
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(Some(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(None).unwrap();
    compressed_buffer = image.to_png(Some(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(None).unwrap();
  let compressed_buffer = image.to_png(Some(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());
}
source

pub fn from_point(x: i32, y: i32) -> Result<Screen>

Examples found in repository?
examples/screenshots.rs (line 34)
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
44
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(Some(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(None).unwrap();
    compressed_buffer = image.to_png(Some(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(None).unwrap();
  let compressed_buffer = image.to_png(Some(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());
}
source

pub fn capture(&self) -> Result<Image>

Examples found in repository?
examples/screenshots.rs (line 11)
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
44
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(Some(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(None).unwrap();
    compressed_buffer = image.to_png(Some(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(None).unwrap();
  let compressed_buffer = image.to_png(Some(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());
}
source

pub fn capture_area( &self, x: i32, y: i32, width: u32, height: u32 ) -> Result<Image>

截取指定区域 区域x,y为相对于当前屏幕的x,y坐标

Examples found in repository?
examples/screenshots.rs (line 21)
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
44
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(Some(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(None).unwrap();
    compressed_buffer = image.to_png(Some(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(None).unwrap();
  let compressed_buffer = image.to_png(Some(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 Clone for Screen

source§

fn clone(&self) -> Screen

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Screen

source§

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

Formats the value using the given formatter. Read more
source§

impl Copy for Screen

Auto Trait Implementations§

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

§

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 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.