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 of image in pixels.

Height of image in pixels.

Vector containing sequence of bytes in RGBA format.

Methods

impl<'a> Image
[src]

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);

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);

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);

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);

Trait Implementations

impl Debug for Image
[src]

Formats the value using the given formatter.