Struct screenshots::Screen
source · pub struct Screen {
pub display_info: DisplayInfo,
}Fields§
§display_info: DisplayInfoImplementations§
source§impl Screen
impl Screen
pub fn new(display_info: &DisplayInfo) -> Self
sourcepub fn all() -> Result<Vec<Screen>>
pub fn all() -> Result<Vec<Screen>>
Examples found in repository?
examples/screenshots.rs (line 6)
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());
}sourcepub fn from_point(x: i32, y: i32) -> Result<Screen>
pub fn from_point(x: i32, y: i32) -> Result<Screen>
Examples found in repository?
examples/screenshots.rs (line 33)
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());
}sourcepub fn capture(&self) -> Result<Image>
pub fn capture(&self) -> Result<Image>
Examples found in repository?
examples/screenshots.rs (line 10)
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());
}sourcepub fn capture_area(
&self,
x: i32,
y: i32,
width: u32,
height: u32
) -> Result<Image>
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 20)
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§
Auto Trait Implementations§
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