Here is some code that works fine:
extern crate image;
extern crate imageproc;
use std::path::Path;
use image::{Rgba, RgbaImage};
use imageproc::drawing::draw_filled_rect_mut;
fn main() {
let path = Path::new("1.png");
let white = Rgba([255u8, 255u8, 255u8, 255u8]);
let red = Rgba([255u8, 0u8, 0u8, 127u8]);
let blue = Rgba([0u8, 0u8, 255u8, 127u8]);
let mut img = RgbaImage::new(200, 200);
draw_filled_rect_mut(&mut img,
imageproc::rect::Rect::at(0, 0).of_size(200, 200),
white);
draw_filled_rect_mut(&mut img,
imageproc::rect::Rect::at(50, 50).of_size(50, 50),
red);
img.save(path).unwrap();
}
However, when I add this code at the end:
let mut img = image::open(path).unwrap();
draw_filled_rect_mut(&mut img,
imageproc::rect::Rect::at(75, 75).of_size(25, 25),
blue);
img.save(path).unwrap();
I get this error:
error[E0061]: this function takes 2 parameters but 1 parameter was supplied
--> src/main.rs:28:9
|
28 | img.save(path).unwrap();
| ^^^^ expected 2 parameters
What I’m trying to do is load in a .png
image, then draw some semi-transparent rectangles on it, then save it back again under the original name.