pub struct ImageRGB8 {
pub width: usize,
pub height: usize,
pub image_data: Vec<[u8; 3]>,
/* private fields */
}Expand description
A struct that holds an RGB image with bit depth of 8
Fields§
§width: usizeThe width of the image
height: usizeThe height of the image
image_data: Vec<[u8; 3]>The image pixel data
Implementations§
Source§impl ImageRGB8
impl ImageRGB8
Sourcepub fn new(width: usize, height: usize, background: [u8; 3]) -> Self
pub fn new(width: usize, height: usize, background: [u8; 3]) -> Self
Returns a new ImageRGB8.
width, height are image dimensions.
background is image’s color.
Sourcepub fn get_pixel(&self, x: usize, y: usize) -> Result<[u8; 3], &'static str>
pub fn get_pixel(&self, x: usize, y: usize) -> Result<[u8; 3], &'static str>
Returns an RGB value of the specified pixel if that pixel exists.
Sourcepub fn set_pixel(&mut self, x: usize, y: usize, color: [u8; 3])
pub fn set_pixel(&mut self, x: usize, y: usize, color: [u8; 3])
Changes the specified pixel to the given color.
If the pixel doesn’t exist, does nothing.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears image_data of any drawings (resets it to the state it was in when ImageRGB8 was created, unless ImageRGB8::set_background_color() was used).
Sourcepub fn set_background_color(&mut self, color: [u8; 3])
pub fn set_background_color(&mut self, color: [u8; 3])
Sets a new color that will be used as background. This only changes internal background data, if you want to apply this to image, call ImageRGB8::clear() after this.
Sourcepub fn draw_line(
&mut self,
x1: usize,
y1: usize,
x2: usize,
y2: usize,
color: [u8; 3],
thickness: usize,
opacity: f64,
)
pub fn draw_line( &mut self, x1: usize, y1: usize, x2: usize, y2: usize, color: [u8; 3], thickness: usize, opacity: f64, )
Draws a new line. x1, y1 are coordinates of the starting point. x2, y2 are coordinates of the ending point.
color defines the color of the line.
thickness defines how thick the line will be. (currently doesn’t do anything). If set to 0, nothing will be drawn.
opacity sets the transparency of the line. <= 0.0 means the line will be completely transparent, while >= 1.0 means the line won’t be transparent.
Sourcepub fn draw_rectangle(
&mut self,
x1: usize,
y1: usize,
x2: usize,
y2: usize,
color: [u8; 3],
thickness: usize,
opacity: f64,
)
pub fn draw_rectangle( &mut self, x1: usize, y1: usize, x2: usize, y2: usize, color: [u8; 3], thickness: usize, opacity: f64, )
Draws a new rectangle. x1, y1 are the coordinates of the first corner, and x2, y2 are the coordinates of the opposite corner.
color defines the color of the rectangle.
thickness defines how thick the rectangle will be. (thickness is added to the inside of the rectangle). If set to 0, the rectangle will be filled.
opacity sets the transparency of the rectangle. <= 0.0 means the rectangle will be completely transparent, while >= 1.0 means the rectangle won’t be transparent.
Sourcepub fn draw_circle(
&mut self,
x: usize,
y: usize,
radius: usize,
color: [u8; 3],
thickness: usize,
opacity: f64,
)
pub fn draw_circle( &mut self, x: usize, y: usize, radius: usize, color: [u8; 3], thickness: usize, opacity: f64, )
Draws a new circle. x, y are the coordinates of the center of the circle.
radius defines the radius of the circle.
color defines the color of the circle.
thickness defines how thick the circle will be. (currently doesn’t do anything). If set to 0, the circle will be filled.
opacity sets the transparency of the circle.
<= 0.0 means the circle will be completely transparent, while >= 1.0 means the circle won’t be transparent.
Sourcepub fn draw_ellipse(
&mut self,
x: usize,
y: usize,
horizontal_axis: usize,
vertical_axis: usize,
color: [u8; 3],
thickness: usize,
opacity: f64,
)
pub fn draw_ellipse( &mut self, x: usize, y: usize, horizontal_axis: usize, vertical_axis: usize, color: [u8; 3], thickness: usize, opacity: f64, )
Draws a new ellipse. x, y are the coordinates of the center of the ellipse.
horizontal_axis defines the half length of the horizontal axis.
vertical_axis defines the half length of the vertical axis.
color defines the color of the ellipse.
thickness defines how thick the ellipse will be. (currently doesn’t do anything). If set to 0, the ellipse will be filled.
opacity sets the transparency of the ellipse.
<= 0.0 means the ellipse will be completely transparent, while >= 1.0 means the ellipse won’t be transparent.