I am trying to draw on an image that may exist or may have to be created. In outline:
fn draw(name: &str) -> Result<()> {
let mut img;
if Path::new(name).exists() {
img = image::open(name)?;
} else {
img = blank_image();
}
draw_details(&mut img)?;
}
fn blank_image() -> DynamicImage {
let bg = Rgba([200u8, 200u8, 200u8, 255u8]);
let mut img = ImageBuffer::new(200, 300);
draw_filled_rect_mut(&mut img, Rect::at(0, 0).of_size(200, 300), bg);
img
}
This doesn't work because blank_image returns an ImageBuffer not a DynamicImage. But is there any way I could return a DynamicImage, so that in both cases the original img in draw can be used?