pub(crate) fn save_rgb_to_image(
raw_pixels: &[u8],
width: u32,
height: u32,
path: impl AsRef<Path>,
) -> Result<()>
Expand description
Saves raw RGB pixel data as a PNG image at the specified path.
Takes a slice of raw RGB pixel data and creates a PNG image file with the specified dimensions. The function handles the conversion from raw bytes to image format and saves the result to disk.
§Arguments
raw_pixels
- A slice of raw RGB pixel data (3 bytes per pixel)width
- The width of the image in pixelsheight
- The height of the image in pixelspath
- The destination file path where the image will be saved
§Returns
Ok(())
if image was successfully savedErr
if conversion or saving failed
§Panics
This function does not panic but returns errors for invalid inputs.
§Examples
let red_pixel = [255u8, 0, 0];
let pixels = red_pixel.repeat(4); // 2x2 image
save_rgb_to_image(&pixels, 2, 2, Path::new("red_square.png"))?;