如何获取光标下的像素颜色?

问题描述 投票:0回答:1

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

这当然可以在任何窗口中工作,而不仅仅是像 winit 窗口这样的“rust 拥有”窗口。

我找到了一些窗口捕获库和其他语言的解决方案,但没有一个能满足我的需求。

rust colors window pixel
1个回答
0
投票

这是一个使用自动驾驶仪的简单跨平台解决方案。

首先使用

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]
    )
}
© www.soinside.com 2019 - 2024. All rights reserved.