wgc 1.0.0

An ergonomic Rust wrapper for Windows.Graphics.Capture API
Documentation

wgc - Windows Graphics Capture Wrapper

Crates.io Documentation License Rust (Windows)

A simple and ergonomic Rust wrapper for Windows.Graphics.Capture API, enabling screen/window capture on Windows 10/11.

Realtime & AI-optimized capture for ML and computer vision workflows.

Features

  • Realtime & AI-optimized: Capture any window or monitor at any resolution and resize in real-time using letterbox scaling. Ideal for ML pipelines, streaming, and computer vision applications.
  • Ergonomic iterator-based API for capturing frames via the Wgc struct
  • Interactive picker dialog for selecting windows or monitors to capture
  • Configurable pixel formats (currently RGBA8 and BGRA8, with more formats planned) via WgcSettings
  • Automatic buffer recreation when capture resolution changes
  • Frame size normalization with letterboxing for consistent output dimensions
  • Optional tracing feature for debug logging
  • Zero-copy frame access with efficient DirectX/Direct2D integration

Requirements

  • Windows 10 October 2018 Update (version 1809) or later
  • Windows 11 (recommended)
  • Rust 2024 edition

Usage

Here's a basic example of how to capture frames:

use wgc::*;

fn main() -> anyhow::Result<()> {
    // Pick an item to capture (window or monitor)
    let item = new_item_with_picker(None)?;

    // Create the capture instance
    let wgc = Wgc::new(item.clone(), Default::default())?;

    // Iterate over captured frames
    for frame in wgc.take(1) {
        let frame = frame?;
        println!("Captured frame from {} with size {:?}",
                 item.clone().DisplayName()?,
                 frame.size()?);
        
        let frame_size = frame.size()?;
        let buffer:Vec<u8> = frame.read_pixels(frame_size)?;
    }
    Ok(())
}

Examples

Check out the examples directory for more detailed usage examples:

  • save_image: Captures a screen item and saves it as an image file to disk.
  • show_image: Captures a screen item and displays it in a window.
  • tutorial: Provides a comprehensive tutorial on wgc for those who wish to leverage most of its features.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.