scrap icon indicating copy to clipboard operation
scrap copied to clipboard

Capture a subset of screen

Open Piping opened this issue 3 years ago • 4 comments

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,

Piping avatar Aug 17 '20 06:08 Piping

Same question here.

dclong avatar Jul 28 '21 17:07 dclong

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,
            ]);
        }
      } 

snaumov avatar Sep 19 '21 01:09 snaumov

@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?

dclong avatar Sep 19 '21 01:09 dclong

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

snaumov avatar Sep 19 '21 14:09 snaumov