Code Monkey home page Code Monkey logo

screenshots-rs's Introduction

screenshots

A cross-platform screenshots library for MacOS、Windows、Linux(X11、wayland).

example

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

    image = screen.capture_area(300, 300, 300, 300).unwrap();
    buffer = image.buffer();
    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.capture_area(300, 300, 300, 300).unwrap();
  let buffer = image.buffer();
  fs::write("target/capture_display_with_point.png", &buffer).unwrap();

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

API

Screen: Screen capturer

  • Screen::new(display_info): Get screen from display info, return Screen.
  • Screen::all(): Get all screen, return Result<Vec<Screen>>.
  • Screen::from_point(x, y): Get screen from point, return Result<Screen>.
  • screen.capture(): capture screen screenshot image, return Result<Image>.
  • screen.capture_area(x, y, width, height): Capture the current screen the designated area, return Result<Image>.

Image: Screen screenshot image

  • Image::new(width, height, buffer): Get image from width、height and rgba buffer, return Image.
  • Image::from_bgra(width, height, buffer): Get image from width、height and bgra buffer, return Result<Image, EncodingError>.
  • image.width(): Get image width, return u32.
  • image.height(): Get image height, return u32.
  • image.buffer(): Get image buffer, return Vec<u8>.

Linux requirements

On Linux, you need to install libxcblibxrandrdbus

Debian/Ubuntu:

apt-get install libxcb1 libxrandr2 libdbus-1-3

Alpine:

apk add libxcb libxrandr dbus

screenshots-rs's People

Contributors

nashaofu avatar joshterrill avatar mdacach avatar radoncoding avatar mokurin000 avatar

Forkers

emily-pa

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.