Skip to content

Commit

Permalink
Stabilize ⭐
Browse files Browse the repository at this point in the history
	modified:   Cargo.lock
	modified:   Cargo.toml
	modified:   README.md
	new file:   src/buffer.rs
	modified:   src/capture.rs
	modified:   src/d3d11.rs
	modified:   src/frame.rs
	new file:   src/graphics_capture_api.rs
	modified:   src/lib.rs
	modified:   src/monitor.rs
	new file:   src/settings.rs
	modified:   src/window.rs
  • Loading branch information
NiiightmareXD committed Oct 20, 2023
1 parent 2393e9c commit f200b66
Show file tree
Hide file tree
Showing 12 changed files with 1,090 additions and 595 deletions.
316 changes: 315 additions & 1 deletion Cargo.lock

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "windows-capture"
version = "1.0.19"
version = "1.0.20"
authors = ["NiiightmareXD"]
edition = "2021"
description = "Windows Capture Simple Screen Capture for Windows 🔥"
description = "Simple Windows Screen Capture Library For Rust And Python 🔥"
documentation = "https://docs.rs/windows-capture"
readme = "README.md"
repository = "https://github.com/NiiightmareXD/windows-capture"
Expand All @@ -18,6 +18,7 @@ categories = [
]

[dependencies]
image = "0.24.7"
log = "0.4.20"
parking_lot = "0.12.1"
thiserror = "1.0.49"
Expand All @@ -26,8 +27,6 @@ windows = { version = "0.51.1", features = [
"Win32_Graphics_Direct3D11",
"Win32_Foundation",
"Graphics_Capture",
"Graphics",
"Foundation",
"Win32_System_WinRT_Direct3D11",
"Win32_System_Threading",
"Win32_UI_WindowsAndMessaging",
Expand All @@ -36,4 +35,6 @@ windows = { version = "0.51.1", features = [
"Win32_Graphics_Gdi",
"System",
"Graphics_DirectX_Direct3D11",
"Foundation_Metadata",
"Win32_UI_HiDpi",
] }
63 changes: 37 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Windows Capture
![Crates.io](https://img.shields.io/crates/l/windows-capture) ![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/NiiightmareXD/windows-capture/rust.yml) ![Crates.io](https://img.shields.io/crates/v/windows-capture)

**Windows Capture** is a highly efficient Rust library that enables you to effortlessly capture the screen using the Graphics Capture API. This library allows you to easily capture the screen of your Windows-based computer and use it for various purposes, such as creating instructional videos, taking screenshots, or recording your gameplay. With its intuitive interface and robust functionality, Windows-Capture is an excellent choice for anyone looking for a reliable and easy-to-use screen capturing solution.
**Windows Capture** is a highly efficient Rust and Python library that enables you to effortlessly capture the screen using the Graphics Capture API. This library allows you to easily capture the screen of your Windows-based computer and use it for various purposes, such as creating instructional videos, taking screenshots, or recording your gameplay. With its intuitive interface and robust functionality, Windows-Capture is an excellent choice for anyone looking for a reliable and easy-to-use screen capturing solution.

## Features

Expand All @@ -16,7 +16,7 @@ Add this library to your `Cargo.toml`:

```toml
[dependencies]
windows-capture = "1.0.19"
windows-capture = "1.0.20"
```
or run this command

Expand All @@ -27,46 +27,57 @@ cargo add windows-capture
## Usage

```rust
use std::time::Instant;

use windows_capture::{
capture::{WindowsCaptureHandler, WindowsCaptureSettings},
frame::Frame,
window::Window,
capture::WindowsCaptureHandler, frame::Frame, settings::WindowsCaptureSettings, window::Window,
};

struct Capture {
fps: usize,
last_output: Instant,
}
struct Capture;

impl WindowsCaptureHandler for Capture {
type Flags = ();
type Flags = String; // To Get The Message (Or A Variable Or ...) From The Settings

fn new(_: Self::Flags) -> Self {
Self {
fps: 0,
last_output: Instant::now(),
}
fn new(message: Self::Flags) -> Self {
// Function That Will Be Called To Create The Struct The Flags Can Be Passed
// From Settings
println!("Got The Message: {message}");

Self {}
}

fn on_frame_arrived(&mut self, _frame: &Frame) {
self.fps += 1;
fn on_frame_arrived(&mut self, frame: Frame) {
// Called Every Time A New Frame Is Available
println!("Got A New Frame");

// Save The Frame As An Image To Specified Path
frame.save_as_image("image.png").unwrap();

if self.last_output.elapsed().as_secs() >= 1 {
println!("{}", self.fps);
self.fps = 0;
self.last_output = Instant::now();
}
// Call To Stop The Capture Thread, You Might Receive A Few More Frames
// Before It Stops
self.stop();
}

fn on_closed(&mut self) {
println!("Closed");
// Called When The Capture Item Closes Usually When The Window Closes,
// Capture Will End After This Function Ends
println!("Capture Item Closed");
}
}

fn main() {
let settings = WindowsCaptureSettings::new(Monitor::get_primary(), true, false, ());
// Checkout Docs For Other Capture Items
let foreground_window = Window::foreground().unwrap();

let settings = WindowsCaptureSettings::new(
// Item To Captue
foreground_window,
// Capture Cursor
Some(true),
// Draw Borders
Some(false),
// This Will Be Passed To The New Function
"It Works".to_string(),
)
.unwrap();

Capture::start(settings).unwrap();
}
Expand Down
24 changes: 24 additions & 0 deletions src/buffer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::alloc::Layout;

/// To Send Raw Pointers Between Threads
pub struct SendPtr<T>(pub *mut T);

impl<T> SendPtr<T> {
pub fn new(ptr: *mut T) -> Self {
Self(ptr)
}
}

unsafe impl<T> Send for SendPtr<T> {}

/// To Save Pointer And It's Layout Together
pub struct Buffer {
pub ptr: *mut u8,
pub layout: Layout,
}

impl Buffer {
pub const fn new(ptr: *mut u8, layout: Layout) -> Self {
Self { ptr, layout }
}
}
Loading

0 comments on commit f200b66

Please sign in to comment.