rust - 创建黑色图片和渐变图片
extern crate image;
extern crate num_complex;
fn main() {
let imgx = 800;
let imgy = 800;
// Create a new ImgBuf with width: imgx and height: imgy
let mut imgbuff = image::ImageBuffer::new(imgx, imgy);
// Iterate over the coordinates and pixels of the image
for (x, y, pixel) in imgbuff.enumerate_pixels_mut() {
let r = 0 * x as u8;
let b = 0 * y as u8;
*pixel = image::Rgb([r, 0, b]);
}
// Save the image as “fractal.png”, the format is deduced from the path
imgbuff.save("fractal.png").unwrap();
}
渐变,替换这2行
let r = (0.3* x as f32) as u8;
let b = (0.3* y as f32) as u8;