rusty-duplication
Capture the screen on Windows using the Desktop Duplication API in Rust, with shared memory support.
Installation
Usage
Basic Usage
use ;
use ;
// create a scanner to scan for monitors
let mut scanner = new.unwrap;
// scanner implements Iterator, you can use it to iterate through monitors
let monitor = scanner.next.unwrap;
// get monitor info
monitor.dxgi_output_desc.unwrap;
monitor.dxgi_outdupl_desc;
// create a vec capturer for a monitor
// this will allocate memory buffer to store pixel data
let mut capturer: VecCapturer = monitor.try_into.unwrap;
// you can also get monitor info from a capturer
let dxgi_outdupl_desc = capturer.monitor.dxgi_outdupl_desc;
let dxgi_output_desc = capturer.monitor.dxgi_output_desc.unwrap;
// get resolution width/height
println!;
// get position
println!;
// sleep for a while before capture to wait system to update the screen
sleep;
// capture desktop image and get the frame info
let info = capturer.capture.unwrap;
// we have some extension methods for the frame info
if info.desktop_updated
if info.mouse_updated
if info.pointer_shape_updated
// write to a file
let mut file = create.unwrap;
// the buffer is in BGRA32 format
file.write_all.unwrap;
Shared Memory
You can use shared memory to share the frame buffer between processes.
use ;
use ;
let monitor = new.unwrap.next.unwrap;
// create a shared memory capturer by creating a shared memory with the provided name
let mut capturer = create.unwrap;
// you can also use `SharedMemoryCapturer::open` to open an existing shared memory
// sleep for a while before capture to wait system to update the screen
sleep;
let info = capturer.capture.unwrap;
assert!;
// write to a file
let mut file = create.unwrap;
// the buffer is in BGRA32 format
file.write_all.unwrap;
[!NOTE] If your shared memory name starts with
Global\, you may need to run your app in administrator mode. See https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createfilemappinga.
Customized Capturer
You can implement CapturerBuffer for your own type to create a customized capturer. You can refer to VecCapturer's implementation.
Examples
Documentation
Credit
This project is based on the following projects:
- https://github.com/bryal/dxgcap-rs
- https://github.com/microsoft/windows-rs
- https://github.com/hecomi/uDesktopDuplication