Struct raster::Image
[−]
[src]
pub struct Image { pub width: i32, pub height: i32, pub bytes: Vec<u8>, }
A struct for easily representing a raster image.
Fields
width: i32
Width of image in pixels.
height: i32
Height of image in pixels.
bytes: Vec<u8>
Vector containing sequence of bytes in RGBA format.
Methods
impl<'a> Image
[src]
fn blank(w: i32, h: i32) -> Image
Create a blank image. Default color is black.
Examples
use raster::Image; let image = Image::blank(2, 2); println!("{:?}", image.bytes); assert_eq!(image.width, 2); assert_eq!(image.height, 2);
fn check_pixel(&self, x: i32, y: i32) -> bool
Check if there is a pixel at this location given by x and y.
Examples
use raster::Image; let image = Image::blank(2, 2); assert_eq!(image.check_pixel(0, 0), true); assert_eq!(image.check_pixel(3, 3), false);
fn get_pixel(&self, x: i32, y: i32) -> Result<Color, String>
Get pixel in a given x and y location of an image.
Examples
use raster::Image; use raster::Color; let mut image = Image::blank(2, 2); // Creates a 2x2 black image. let pixel = image.get_pixel(0, 0).unwrap(); assert_eq!(0, pixel.r); assert_eq!(0, pixel.g); assert_eq!(0, pixel.b); assert_eq!(255, pixel.a);
fn set_pixel(&mut self, x: i32, y: i32, color: Color) -> Result<(), String>
Set pixel in a given x and y location of an image.
Examples
use raster::Image; use raster::Color; let mut image = Image::blank(2, 2); // Creates a 2x2 black image. let _ = image.set_pixel(0, 0, Color::rgba(255, 0, 0, 255)); // Set first pixel to red let pixel = image.get_pixel(0, 0).unwrap(); assert_eq!(255, pixel.r); assert_eq!(0, pixel.g); assert_eq!(0, pixel.b); assert_eq!(255, pixel.a);