Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Write A Pixel To An Image In Rust

This creates a 1x1 pixel image, writes a red pixel to it before saving it

Code

```cargo
[dependencies]
image = "0.25.1"
```

use image::{RgbImage, Rgb};

fn main() {
  let mut img = RgbImage::new(1,1);
  img.put_pixel(0, 0, Rgb([255, 0, 0]));
  match img.save("pixel.png") {
    Ok(_) => println!("Saved image"),
    Err(e) => println!("Error: {}", e)
  }
}

Results

Saved image

References