scrap
scrap copied to clipboard
Capture a subset of screen
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,
Same question here.
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 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?
doesn't seem there is an API for that yet, but method frame
can be updated to accept an optional Rect
argument I think