Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture a subset of screen #33

Open
Piping opened this issue Aug 17, 2020 · 4 comments
Open

Capture a subset of screen #33

Piping opened this issue Aug 17, 2020 · 4 comments

Comments

@Piping
Copy link

Piping commented Aug 17, 2020

Hi,

From the api, it was not clear to me how to get a subset of screen.

For example, I want to a bounding box 200x200 px captured at the center of my display.

How should I go about using the api?

Best,

@dclong
Copy link

dclong commented Jul 28, 2021

Same question here.

@snaumov
Copy link

snaumov commented Sep 19, 2021

assuming you know (top, left, width, height) of the area, you can change the example to limit the bytes stored in data array to those in the area:

      let top = window_position.y as usize;
      let left = window_position.x as usize;
      let width = window_size.width as usize;
      let height = window_size.height as usize;

      let mut bitflipped = Vec::with_capacity(width * height * 4);

      for y in top..(top + height) {
        for x in left..(left + width) {
            let i = stride * y + 4 * x;
            bitflipped.extend_from_slice(&[
                buffer[i + 2],
                buffer[i + 1],
                buffer[i],
                255,
            ]);
        }
      } 

@dclong
Copy link

dclong commented Sep 19, 2021

@snaumov Yep, that's what I wanted to try first. However, is this the most efficiently approach? It takes a screenshot of the whole screen and then crop to get the area we want. Does the underlying APIs support take screenshot of a specific area directly?

@snaumov
Copy link

snaumov commented Sep 19, 2021

doesn't seem there is an API for that yet, but method frame can be updated to accept an optional Rect argument I think

2021-09-19_10-26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants