win-screenshot
Take a screenshot of a specific window or entire screen on Windows platform
Known Issues
capture_window() draws black border for some windows
If you call capture_window() and got 0x80070578 "invalid window handle" make sure captured window is not minimized
Minimum requirements
capture_window() uses undocumented PW_RENDERFULLCONTENT which first appeared in Windows 8.1
Examples
use image::RgbaImage;
use regex::Regex;
use win_screenshot::prelude::*;
fn main() {
let buf = capture_display().unwrap();
let buf = capture_window(11996706).unwrap();
let hwnd = find_window("Notepad").unwrap();
let buf = capture_window(hwnd).unwrap();
let re = Regex::new(r"Steam").unwrap();
let hwnd = window_list()
.unwrap()
.iter()
.find(|i| re.is_match(&i.window_name))
.unwrap()
.hwnd;
let buf = capture_window(hwnd).unwrap();
let img = RgbaImage::from_raw(buf.width, buf.height, buf.pixels).unwrap();
img.save("screenshot.jpg").unwrap();
let using = Using::BitBlt;
let using = Using::PrintWindow;
let area = Area::ClientOnly;
let area = Area::Full;
let crop_xy = None; let crop_wh = None; let buf = capture_window_ex(hwnd, using, area, crop_xy, crop_wh).unwrap();
}