Created
April 8, 2018 17:31
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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