In this example we create an empty image using the image crate of Rust.
This is the result:
Yes, this is just a black square.
cargo new create-empty-image
cd create-empty-image
cargo add image
Results in the following file:
examples/create-empty-image/Cargo.toml
[package]
name = "create-empty-image"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
image = "0.24"
Then we add the code:
examples/create-empty-image/src/main.rs
use image::{RgbImage, ImageBuffer};
fn main() {
empty();
}
fn empty() {
let width = 200;
let height = 200;
let img: RgbImage = ImageBuffer::new(width, height);
img.save("empty.png").unwrap();
}
and run
cargo run