📷 Screenshots

Screenshots is a cross-platform screenshots library for MacOS, Windows, Linux (X11, Wayland) written in Rust. It provides a simple API for capturing screenshots of a screen or a specific area of a screen.

Example

The following example shows how to capture screenshots of all screens and a specific area of a screen.

```rust use screenshots::{Screen, Compression}; use std::{fs, time::Instant};

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.topng(Compression::Best).unwrap(); fs::write(format!("target/{}.png", screen.displayinfo.id), buffer).unwrap();

image = screen.capture_area(300, 300, 300, 300).unwrap();
buffer = image.to_png(None).unwrap();
fs::write(format!("target/{}-2.png", screen.display_info.id), buffer).unwrap();

}

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

let image = screen.capturearea(300, 300, 300, 300).unwrap(); let buffer = image.topng(Compression::Fast).unwrap(); fs::write("target/capturedisplaywith_point.png", buffer).unwrap();

println!("运行耗时: {:?}", start.elapsed()); } ```

API

Screen

The Screen struct represents a screen capturer and provides the following methods:

Image

The Image struct represents a screen screenshot image and provides the following methods:

Linux Requirements

On Linux, you need to install libxcb, libxrandr, and dbus.

Debian/Ubuntu:

sh apt-get install libxcb1 libxrandr2 libdbus-1-3

Alpine:

sh apk add libxcb libxrandr dbus

License

This project is licensed under the Apache License. See the LICENSE file for details.