#screenshot #screen #capture

screenshots

A cross-platform screen capturer library

36 releases (8 breaking)

new 0.8.3 Sep 19, 2023
0.7.3 Aug 13, 2023
0.7.0 Jul 23, 2023
0.5.3 Mar 12, 2023
0.0.3 Mar 29, 2022

#38 in Images

Download history 554/week @ 2023-06-01 898/week @ 2023-06-08 856/week @ 2023-06-15 515/week @ 2023-06-22 426/week @ 2023-06-29 550/week @ 2023-07-06 583/week @ 2023-07-13 457/week @ 2023-07-20 551/week @ 2023-07-27 445/week @ 2023-08-03 506/week @ 2023-08-10 507/week @ 2023-08-17 513/week @ 2023-08-24 897/week @ 2023-08-31 725/week @ 2023-09-07 670/week @ 2023-09-14

2,889 downloads per month
Used in 9 crates

Apache-2.0

30KB
726 lines

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

use screenshots::Screen;
use std::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();
        image
            .save(format!("target/{}.png", screen.display_info.id))
            .unwrap();

        image = screen.capture_area(300, 300, 300, 300).unwrap();
        image
            .save(format!("target/{}-2.png", screen.display_info.id))
            .unwrap();
    }

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

    let image = screen.capture_area(300, 300, 300, 300).unwrap();
    image.save("target/capture_display_with_point.png").unwrap();
    println!("运行耗时: {:?}", start.elapsed());
}

API

Screen

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

  • Screen::new(display_info): Get a screen from the display info, returns a Screen.
  • Screen::all(): Get all screens, returns Result<Vec<Screen>>.
  • Screen::from_point(x, y): Get a screen from a point, returns Result<Screen>.
  • screen.capture(): Capture a screenshot of the screen, returns a image as Result<RgbaImage>.
  • screen.capture_area(x, y, width, height): Capture a screenshot of the designated area of the screen, returns the same as capture().

Linux Requirements

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

Debian/Ubuntu:

apt-get install libxcb1 libxrandr2 libdbus-1-3

Alpine:

apk add libxcb libxrandr dbus

License

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

Dependencies

~5–60MB
~1M SLoC