wgc 0.0.3

A simple wrapper for Windows Graphics Capture
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.

Features

  • Easy-to-use iterator interface for capturing frames
  • Support for capturing windows, monitors
  • Automatic handling of resolution changes during capture
  • Optional tracing support for debugging
  • Low-level access to Direct3D11 frames when needed

Requirements

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

Installation

Add this to your Cargo.toml:

[dependencies]
wgc = "*"

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(())
}

To enable tracing for debugging output, add the tracing feature and initialize a subscriber:

[dependencies]
wgc = { version = "*", features = ["tracing"] }
tracing-subscriber = "0.3"

Run with environment variable for verbose output:

set RUST_LOG=trace
cargo run --example hello_world --features tracing

Or in PowerShell:

$env:RUST_LOG="trace"
cargo run --example hello_world --features tracing

Examples

Check out the examples directory for more detailed usage examples:

  • save_image.rs: Captures a screen item and saves it as a PNG file to disk.
  • show_image.rs: Captures a screen item and displays it in a window.

Development Status

This crate is currently under active development. Features may be added, removed, or changed in future releases. Please check back regularly for updates.

API stability is not guaranteed until version 1.0.0 is released.

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.