Skip to content

Commit

Permalink
Merge pull request #92 from Fangoboyo/main
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
NiiightmareXD authored Nov 1, 2024
2 parents 459ff17 + 3fded03 commit c9b9cc0
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

## Features

- Only Updates The Frame When Required.
- High Performance.
- Easy To Use.
- Only updates the frame when required.
- High performance.
- Easy to use.
- Latest Screen Capturing API.

## Installation

Add this library to your `Cargo.toml`:
Add this dependency to your `Cargo.toml`:

```toml
[dependencies]
Expand Down Expand Up @@ -50,7 +50,7 @@ use windows_capture::{
settings::{ColorFormat, CursorCaptureSettings, DrawBorderSettings, Settings},
};

// This struct will be used to handle the capture events.
// Handles capture events.
struct Capture {
// The video encoder that will be used to encode the frames.
encoder: Option<VideoEncoder>,
Expand All @@ -62,12 +62,12 @@ impl GraphicsCaptureApiHandler for Capture {
// The type of flags used to get the values from the settings.
type Flags = String;

// The type of error that can occur during capture, the error will be returned from `CaptureControl` and `start` functions.
// The type of error that can be returned from `CaptureControl` and `start` functions.
type Error = Box<dyn std::error::Error + Send + Sync>;

// Function that will be called to create the struct. The flags can be passed from settings.
// Function that will be called to create a new instance. The flags can be passed from settings.
fn new(ctx: Context<Self::Flags>) -> Result<Self, Self::Error> {
println!("Got The Flag: {}", ctx.flags);
println!("Created with Flags: {}", ctx.flags);

let encoder = VideoEncoder::new(
VideoSettingsBuilder::new(1920, 1080),
Expand Down Expand Up @@ -97,7 +97,7 @@ impl GraphicsCaptureApiHandler for Capture {
// Send the frame to the video encoder
self.encoder.as_mut().unwrap().send_frame(frame)?;

// Note: The frame has other uses too for example you can save a single for to a file like this:
// Note: The frame has other uses too, for example, you can save a single frame to a file, like this:
// frame.save_as_image("frame.png", ImageFormat::Png)?;
// Or get the raw data like this so you have full control:
// let data = frame.buffer()?;
Expand All @@ -118,32 +118,32 @@ impl GraphicsCaptureApiHandler for Capture {

// Optional handler called when the capture item (usually a window) closes.
fn on_closed(&mut self) -> Result<(), Self::Error> {
println!("Capture Session Closed");
println!("Capture session ended");

Ok(())
}
}

fn main() {
// Gets The Foreground Window, Checkout The Docs For Other Capture Items
// Gets the foreground window, refer to the docs for other capture items
let primary_monitor = Monitor::primary().expect("There is no primary monitor");

let settings = Settings::new(
// Item To Captue
// Item to capture
primary_monitor,
// Capture Cursor Settings
// Capture cursor settings
CursorCaptureSettings::Default,
// Draw Borders Settings
// Draw border settings
DrawBorderSettings::Default,
// The desired color format for the captured frame.
ColorFormat::Rgba8,
// Additional flags for the capture settings that will be passed to user defined `new` function.
"Yea This Works".to_string(),
"Yea this works".to_string(),
);

// Starts the capture and takes control of the current thread.
// The errors from handler trait will end up here
Capture::start(settings).expect("Screen Capture Failed");
Capture::start(settings).expect("Screen capture failed");
}
```

Expand Down

0 comments on commit c9b9cc0

Please sign in to comment.