pub struct Screen {
pub display_info: DisplayInfo,
}
Expand description
This struct represents a screen capturer.
Fields§
§display_info: DisplayInfo
Implementations§
Source§impl Screen
impl Screen
Sourcepub fn new(display_info: &DisplayInfo) -> Self
pub fn new(display_info: &DisplayInfo) -> Self
Get a screen from the display_info.
Sourcepub fn all() -> Result<Vec<Screen>>
pub fn all() -> Result<Vec<Screen>>
Return all available screens.
Examples found in repository?
examples/screenshots.rs (line 6)
4fn main() {
5 let start = Instant::now();
6 let screens = Screen::all().unwrap();
7
8 for screen in screens {
9 println!("capturer {screen:?}");
10 let mut image = screen.capture().unwrap();
11 image
12 .save(format!("target/{}.png", screen.display_info.id))
13 .unwrap();
14
15 image = screen.capture_area(300, 300, 300, 300).unwrap();
16 image
17 .save(format!("target/{}-2.png", screen.display_info.id))
18 .unwrap();
19 }
20
21 let screen = Screen::from_point(100, 100).unwrap();
22 println!("capturer {screen:?}");
23
24 let image = screen.capture_area(300, 300, 300, 300).unwrap();
25 image.save("target/capture_display_with_point.png").unwrap();
26 println!("运行耗时: {:?}", start.elapsed());
27}
Sourcepub fn from_point(x: i32, y: i32) -> Result<Screen>
pub fn from_point(x: i32, y: i32) -> Result<Screen>
Get a screen which includes the point with the given coordinates.
Examples found in repository?
examples/screenshots.rs (line 21)
4fn main() {
5 let start = Instant::now();
6 let screens = Screen::all().unwrap();
7
8 for screen in screens {
9 println!("capturer {screen:?}");
10 let mut image = screen.capture().unwrap();
11 image
12 .save(format!("target/{}.png", screen.display_info.id))
13 .unwrap();
14
15 image = screen.capture_area(300, 300, 300, 300).unwrap();
16 image
17 .save(format!("target/{}-2.png", screen.display_info.id))
18 .unwrap();
19 }
20
21 let screen = Screen::from_point(100, 100).unwrap();
22 println!("capturer {screen:?}");
23
24 let image = screen.capture_area(300, 300, 300, 300).unwrap();
25 image.save("target/capture_display_with_point.png").unwrap();
26 println!("运行耗时: {:?}", start.elapsed());
27}
Sourcepub fn capture(&self) -> Result<RgbaImage>
pub fn capture(&self) -> Result<RgbaImage>
Capture a screenshot of the screen.
Examples found in repository?
examples/screenshots.rs (line 10)
4fn main() {
5 let start = Instant::now();
6 let screens = Screen::all().unwrap();
7
8 for screen in screens {
9 println!("capturer {screen:?}");
10 let mut image = screen.capture().unwrap();
11 image
12 .save(format!("target/{}.png", screen.display_info.id))
13 .unwrap();
14
15 image = screen.capture_area(300, 300, 300, 300).unwrap();
16 image
17 .save(format!("target/{}-2.png", screen.display_info.id))
18 .unwrap();
19 }
20
21 let screen = Screen::from_point(100, 100).unwrap();
22 println!("capturer {screen:?}");
23
24 let image = screen.capture_area(300, 300, 300, 300).unwrap();
25 image.save("target/capture_display_with_point.png").unwrap();
26 println!("运行耗时: {:?}", start.elapsed());
27}
Sourcepub fn capture_area(
&self,
x: i32,
y: i32,
width: u32,
height: u32,
) -> Result<RgbaImage>
pub fn capture_area( &self, x: i32, y: i32, width: u32, height: u32, ) -> Result<RgbaImage>
Captures a screenshot of the designated area of the screen.
Examples found in repository?
examples/screenshots.rs (line 15)
4fn main() {
5 let start = Instant::now();
6 let screens = Screen::all().unwrap();
7
8 for screen in screens {
9 println!("capturer {screen:?}");
10 let mut image = screen.capture().unwrap();
11 image
12 .save(format!("target/{}.png", screen.display_info.id))
13 .unwrap();
14
15 image = screen.capture_area(300, 300, 300, 300).unwrap();
16 image
17 .save(format!("target/{}-2.png", screen.display_info.id))
18 .unwrap();
19 }
20
21 let screen = Screen::from_point(100, 100).unwrap();
22 println!("capturer {screen:?}");
23
24 let image = screen.capture_area(300, 300, 300, 300).unwrap();
25 image.save("target/capture_display_with_point.png").unwrap();
26 println!("运行耗时: {:?}", start.elapsed());
27}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Screen
impl RefUnwindSafe for Screen
impl Send for Screen
impl Sync for Screen
impl Unpin for Screen
impl UnwindSafe for Screen
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more