Skip to content

Commit

Permalink
chore: 修改文档
Browse files Browse the repository at this point in the history
  • Loading branch information
nashaofu committed Jan 29, 2024
1 parent 3eb7c5c commit be6f6ab
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "xcap"
version = "0.0.2"
version = "0.0.3"
edition = "2021"
description = "A cross-platform screen capture library"
description = "XCap is a cross-platform screen capture library written in Rust. It supports Linux (X11, Wayland), MacOS, and Windows. XCap supports screenshot and video recording (to be implemented)."
license = "Apache-2.0"
documentation = "https://docs.rs/xcap"
homepage = "https://github.com/nashaofu/xcap"
Expand Down
118 changes: 118 additions & 0 deletions README-zh_CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# XCap

[English](README.md) | 简体中文

XCap 是一个使用 Rust 编写的跨平台的屏幕捕获库,它支持 Linux(X11,Wayland)、MacOS 与 Windows。XCap 支持截图与视频录制(待实现)。

## 功能

- 跨平台: 支持 Linux(X11,Wayland)、MacOS 与 Windows。
- 支持多种截图模式: 可以对屏幕与窗口进行截图。
- 支持视频录制:支持对屏幕或窗口进行录制(待实现)。

## 例子

- 屏幕截图

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

fn normalized(filename: &str) -> String {
filename
.replace("|", "")
.replace("\\", "")
.replace(":", "")
.replace("/", "")
}

fn main() {
let start = Instant::now();
let monitors = Monitor::all().unwrap();

for monitor in monitors {
let image = monitor.capture_image().unwrap();

image
.save(format!("target/monitor-{}.png", normalized(monitor.name())))
.unwrap();
}

println!("运行耗时: {:?}", start.elapsed());
}
```

- 窗口截图

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

fn normalized(filename: &str) -> String {
filename
.replace("|", "")
.replace("\\", "")
.replace(":", "")
.replace("/", "")
}

fn main() {
let start = Instant::now();
let windows = Window::all().unwrap();

let mut i = 0;

for window in windows {
// 最小化的窗口不能截屏
if window.is_minimized() {
continue;
}

println!(
"Window: {:?} {:?} {:?}",
window.title(),
(window.x(), window.y(), window.width(), window.height()),
(window.is_minimized(), window.is_maximized())
);

let image = window.capture_image().unwrap();
image
.save(format!(
"target/window-{}-{}.png",
i,
normalized(window.title())
))
.unwrap();

i += 1;
}

println!("运行耗时: {:?}", start.elapsed());
}
```

## Linux 系统要求

在 Linux 上,需要安装 `libxcb`, `libxrandr``dbus`.

Debian/Ubuntu:

```sh
apt-get install libxcb1 libxrandr2 libdbus-1-3
```

Alpine:

```sh
apk add libxcb libxrandr dbus
```

ArchLinux:

```sh
pacman -S libxcb libxrandr dbus
```

## License

本项目采用 Apache 许可证。详情请查看 [LICENSE](./LICENSE) 文件。
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# 📷 XCap
# XCap

XCap is a cross-platform screen capture library for MacOS, Windows, Linux (X11, Wayland) written in Rust. It provides a simple API for capturing screen capture of a screen or a specific area of a screen.
English | [简体中文](README-zh_CN.md)

XCap is a cross-platform screen capture library written in Rust. It supports Linux (X11, Wayland), MacOS, and Windows. XCap supports screenshot and video recording (to be implemented).

## Features

- Cross-platform support: Windows Mac and Linux.
- Multiple capture modes: screen window.
- Video capture、audio capture soon.
- Cross-platform: Supports Linux (X11, Wayland), MacOS, and Windows.
- Supports multiple screenshot modes: Can take screenshots of the screen and windows.
- Supports video recording: Supports recording of the screen or window (to be implemented).

## Example
## Examples

- Monitor capture
- Screen Capture

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

fn normalized(filename: &str) -> String {
filename
Expand All @@ -40,11 +42,11 @@ fn main() {
}
```

- Window capture
- Window Capture

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

fn normalized(filename: &str) -> String {
filename
Expand Down Expand Up @@ -89,7 +91,7 @@ fn main() {
}
```

## Linux Requirements
## Linux System Requirements

On Linux, you need to install `libxcb`, `libxrandr`, and `dbus`.

Expand All @@ -113,4 +115,4 @@ pacman -S libxcb libxrandr dbus

## License

This project is licensed under the Apache License. See the [LICENSE](../LICENSE) file for details.
This project is licensed under the Apache License. See the [LICENSE](./LICENSE) file for details.
4 changes: 3 additions & 1 deletion src/utils/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ pub fn bgra_to_rgba_image(width: u32, height: u32, buf: Vec<u8>) -> XCapResult<R
for src in rgba_buf.chunks_exact_mut(4) {
src.swap(0, 2);
// fix https://github.com/nashaofu/xcap/issues/92#issuecomment-1910014951
src[3] = 255;
if src[3] == 0 {
src[3] = 255;
}
}

vec_to_rgba_image(width, height, rgba_buf)
Expand Down

0 comments on commit be6f6ab

Please sign in to comment.