Struct screenshots::Image
source · pub struct Image { /* private fields */ }Implementations§
source§impl Image
impl Image
pub fn new(width: u32, height: u32, rgba: Vec<u8>) -> Self
pub fn from_bgra( bgra: Vec<u8>, width: u32, height: u32, bytes_per_row: usize ) -> Self
pub fn width(&self) -> u32
pub fn height(&self) -> u32
pub fn rgba(&self) -> &Vec<u8>
sourcepub fn to_png(
&self,
compression: Option<Compression>
) -> Result<Vec<u8>, EncodingError>
pub fn to_png( &self, compression: Option<Compression> ) -> Result<Vec<u8>, EncodingError>
Examples found in repository?
examples/screenshots.rs (line 12)
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§
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> 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