From 274087eae33cecdd4728d1b45bf85453b887decc Mon Sep 17 00:00:00 2001 From: alpapie Date: Sun, 28 Apr 2024 19:52:46 +0000 Subject: [PATCH] feat: add more backgroundcolor for new image --- src/image.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/image.rs b/src/image.rs index d886a865b..08ec004ab 100644 --- a/src/image.rs +++ b/src/image.rs @@ -51,6 +51,36 @@ impl<'a> Image { } } + // Create a blank image. Default color is white. + pub fn white(w: i32, h: i32) -> Image { + let mut bytes = Vec::with_capacity((w * h) as usize * 4); + for _ in 0..h { + for _ in 0..w { + bytes.extend_from_slice(&[255, 255, 255, 255]); + } + } + Image { + width: w, + height: h, + bytes: bytes, + } + } + + // Create a blank image. Default color is white. + pub fn rand_color(w: i32, h: i32,color: Color) -> Image { + let mut bytes = Vec::with_capacity((w * h) as usize * 4); + for _ in 0..h { + for _ in 0..w { + bytes.extend_from_slice(&[color.r, color.g, color.b, 255]); + } + } + Image { + width: w, + height: h, + bytes: bytes, + } + } + /// Check if there is a pixel at this location given by x and y. /// /// # Examples