Struct bmp::Image [-] [+] [src]

pub struct Image {
    // some fields omitted
}

The image type provided by the library.

It exposes functions to initialize or read BMP images from disk, common modification of pixel data, and saving to disk.

The image is accessed in row-major order from top to bottom, where point (0, 0) is defined to be in the upper left corner of the image.

Currently, only uncompressed BMP images are supported.

Methods

impl Image

fn new(width: u32, height: u32) -> Image

Returns a new BMP Image with the width and height specified. It is initialized to a black image by default.

Example

extern crate bmp;

let mut img = bmp::Image::new(100, 80);

fn get_width(&self) -> u32

Returns the width of the Image.

fn get_height(&self) -> u32

Returns the height of the Image.

fn set_pixel(&mut self, x: u32, y: u32, val: Pixel)

Set the pixel value at the position of width and height.

Example

extern crate bmp;

let mut img = bmp::Image::new(100, 80);
img.set_pixel(10, 10, bmp::consts::RED);

fn get_pixel(&self, x: u32, y: u32) -> Pixel

Returns the pixel value at the position of width and height.

Example

extern crate bmp;

let img = bmp::Image::new(100, 80);
assert_eq!(bmp::consts::BLACK, img.get_pixel(10, 10));

fn coordinates(&self) -> ImageIndex

Returns a new ImageIndex that iterates over the image dimensions in top-bottom order.

Example

extern crate bmp;

let mut img = bmp::Image::new(100, 100);
for (x, y) in img.coordinates() {
    img.set_pixel(x, y, bmp::consts::BLUE);
}

fn save(&self, name: &str) -> Result<()>

Saves the image to the path specified by name. The function will overwrite the contents if a file already exists with the same name.

The function returns the io::Result from the underlying Reader.

Example

extern crate bmp;

let mut img = bmp::Image::new(100, 100);
let _ = img.save("black.bmp").unwrap_or_else(|e| {
    panic!("Failed to save: {}", e)
});

Trait Implementations

impl Debug for Image

fn fmt(&self, f: &mut Formatter) -> Result<(), Error>

Derived Implementations

impl PartialEq for Image

fn eq(&self, __arg_0: &Image) -> bool

fn ne(&self, __arg_0: &Image) -> bool

impl Eq for Image

impl Clone for Image

fn clone(&self) -> Image

fn clone_from(&mut self, source: &Self)