4 releases (breaking)

0.3.0 Jul 18, 2024
0.2.0 Jul 18, 2024
0.1.0 Jul 17, 2024
0.0.0 Jul 17, 2024

#318 in Images

MPL-2.0 license

26KB
661 lines

winc - Windows Capture

A crate for windows screen capture.

Usage

See tests.rs for examples.

#[test]
fn region_screenshots() {
    let monitors = get_all_monitors().unwrap();
    let mut capturers = Vec::new();

    for monitor in monitors {
        let p0 = monitor.info.rect.top_left();
        let p1 = p0.translate(100, 100);
        let region = RECT::from_corners(p0, p1).translate(100, 100);
        let capturer = get_monitor_capturer(Rc::new(monitor), region);
        capturers.push(capturer);
    }
    std::fs::create_dir_all("target/capture").unwrap();

    let mut images = Vec::new();
    for capturer in capturers.iter() {
        // capture
        let capture = capturer.capture(&mut Metrics::None).unwrap();

        // save image
        let mon_name_good = capturer.monitor.info.name.replace(r"\\.\", "");
        let path = format!("target/capture/region-{}.png", mon_name_good);
        capture.save(path).unwrap();
        images.push(capture);
    }

    assert_no_transparency(&images);
}

Attributions

Some code from https://github.com/TeamDman/Cursor-Hero which used some code from https://github.com/nashaofu/screenshots-rs/ commit 999faac06f85bd93638c2a9cda6cbb25ad9f5c73

My understanding is that the licenses used in our projects are compatible. If something is wrong, please let me know!

The modifications aim to reduce redundant work for successive screen capture calls.

Might also be interesting:

Dependencies

~132MB
~2M SLoC