INNER CODE UNIT · Rust
get_color
autopilot-rs/autopy · src/bitmap.rs:155
fn get_color(&self, x: f64, y: f64) -> PyResult<u32> {
let point = Point::new(x, y);
if !self.bitmap.bounds().is_point_visible(point) {
Err(pyo3::exceptions::PyValueError::new_err(format!(
"Point out of bounds {}",
point
)))
} else {
let rgb = self.bitmap.get_pixel(point);
let channels = rgb.channels();
Ok(rgb_to_hex(channels[0], channels[1], channels[2]))
}
}
/// Attempts to find `color` inside `rect` of the form `((x, y), (width,
/// height))` in `bmp` from the given `start_point`. Returns coordinates if
/// found, or `None` if not. If `rect` is `None`, `bmp.bounds` is used
/// instead. If `start_point` is `None`, the origin of `rect` is used.