Skip to content

Instantly share code, notes, and snippets.

@newton-migosi
Created April 8, 2018 17:31
Show Gist options
  • Save newton-migosi/b0ea781e0d7fc59b98c5303169e0eb9a to your computer and use it in GitHub Desktop.
Save newton-migosi/b0ea781e0d7fc59b98c5303169e0eb9a to your computer and use it in GitHub Desktop.
Generating a red image using Rust. Simple demo of Rust program flow.
extern crate image;
use std::fs::File;
use std::path::Path;
fn main(){
let image_size = 300;
let mut image_buf = image::ImageBuffer::new(image_size, image_size);
let red = [255, 0, 0];
for (_, _, pixel) in image_buf.enumerate_pixels_mut(){
*pixel = image::Rgb(red);
}
let img_path = Path::new("red.png");
let ref mut img_file = File::create(&img_path).unwrap();
let _ = image::ImageRgb8(image_buf).save(img_file, image::PNG);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment