#screenshot #display #window #windows #screen

win-screenshot

Take a screenshot from specified window or entire screen on Windows platform

12 releases (5 stable)

Uses new Rust 2021

2.0.0 Jul 7, 2022
1.0.3 Jul 3, 2022
1.0.2 Jun 7, 2022
0.1.6 Jun 3, 2022
0.1.3 May 15, 2022

#10 in #screenshot

28 downloads per month

MIT/Apache

14KB
269 lines

win-screenshot

Take a screenshot from specified window or entire screen on Windows platform

Known Issues

capture_window() draws black border for some windows

Minimum requirements

capture_window() uses undocumented PW_RENDERFULLCONTENT which first appeared in Windows 8.1

Examples

use regex::Regex;
use win_screenshot::addon::*;
use win_screenshot::capture::*;

fn main() {
    // capture entire screen
    let s = capture_display().unwrap();

    // capture window by known id
    let s = capture_window(11996706, Area::Full).unwrap();

    // capture window client area
    let s = capture_window(11996706, Area::ClientOnly).unwrap();

    // capture window if you know the exact name
    let s = capture_window(find_window("Notepad").unwrap(), Area::Full).unwrap();

    // if you don't know the exact name, try to find it
    let re = Regex::new(r"Firefox").unwrap();
    let hwnd = window_list()
        .unwrap()
        .iter()
        .find(|i| re.is_match(&i.window_name))
        .unwrap()
        .hwnd;
    let s = capture_window(hwnd, Area::Full)
        .unwrap();

    s.save("screenshot.jpg").unwrap();
}

Dependencies

~195MB
~3.5M SLoC