Create empty image with the image crate of Rust

image empty RgbImage ImageBuffer save

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:


name = "create-empty-image"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at

image = "0.24"

Then we add the code:


use image::{RgbImage, ImageBuffer};

fn main() {

fn empty() {
    let width = 200;
    let height = 200;

    let img: RgbImage = ImageBuffer::new(width, height);"empty.png").unwrap();

and run

cargo run

Related Pages

Image - a crate to generate and manipulate images in Rust
Create empty image with white background and black borders using Rust
Create and image and draw a line in Rust


Gabor Szabo (szabgab)

Gabor Szabo, the author of the Rust Maven web site maintains several Open source projects in Rust and while he still feels he has tons of new things to learn about Rust he already offers training courses in Rust and still teaches Python, Perl, git, GitHub, GitLab, CI, and testing.

Gabor Szabo