我正在寻找一种方法来获取光标下的像素颜色值。
这当然可以在任何窗口中工作,而不仅仅是像 winit 窗口这样的“rust 拥有”窗口。
这是一个使用自动驾驶仪的简单跨平台解决方案。
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]
)
}