我正在寻找一种方法来获得光标下的像素 colored颜色 值.

这当然可以在任何windows 上使用,而不仅仅是像Winit这样的"铁 rust 拥有的"windows .

我找到了几个library of window capturesolution in other language ,但都不能满足我的需要.

推荐答案

下面是一个使用autopilot的简单跨平台解决方案.

首先使用mouse::location()获取光标位置,然后使用screen::get_color(position)获取屏幕上的像素.

完整的样本:

fn main() {
    let mouse_location = autopilot::mouse::location();
    let pixel = autopilot::screen::get_color(mouse_location).unwrap();
    println!(
        "Pixel color under cursor (RGBA): {},{},{},{}",
        pixel.0[0], pixel.0[1], pixel.0[2], pixel.0[3]
    )
}

Rust相关问答推荐

在actix—web中使用Redirect或NamedFile响应

有没有办法模仿对象安全克隆?

异步FN中的 rust 递归

铁 rust 中的泛型:不能将`<;T作为添加>;::Output`除以`{Float}`

如何从ruust中的fig.toml中读取?

如何使用reqwest进行异步请求?

是否可以在不直接重复的情况下为许多特定类型实现一个函数?

如何从borrow 的异步代码运行阻塞代码?

为什么我们有两种方法来包含 serde_derive?

Rust:为什么 Pin 必须持有指针?

在Rust中实现Trie数据 struct 的更好方式

全面的 Rust Ch.16.2 - 使用捕获和 const 表达式的 struct 模式匹配

Rust 打包在 .deb 中

为什么这段 Rust 代码会在没有递归或循环的情况下导致堆栈溢出?

如何从 rust 中的同一父目录导入文件

有没有办法隐式绑定 let/match 操作的成员?

如何从 x86_64 Mac 构建 M1 Mac?

为什么 Rust 编译器在移动不可变值时执行复制?

当 `T` 没有实现 `Debug` 时替代 `unwrap()`

`if let` 只是另一种编写其他 `if` 语句的方式吗?