INNER CODE UNIT · Rust

save

autopilot-rs/autopy · src/bitmap.rs:101

    fn save(&self, path: &str, format: Option<&str>) -> PyResult<()> {
        let format = format
            .or(Path::new(path).extension().and_then(|x| x.to_str()))
            .unwrap_or("");
        let fmt = image_output_format_from_extension(format);
        let ref mut buffer = File::create(path)?;
        self.bitmap
            .image
            .write_to(buffer, ImageFormat::try_from(fmt)?)
            .map_err(FromImageError::from)?;
        Ok(())
    }

    /// Copies image to pasteboard. Currently only supported on macOS.
    ///
    /// Exceptions:
    ///     - `IOError` is thrown if the image could not be copied.
    ///     - `ValueError` is thrown if the image was too large or small.

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…