[][src]Struct bmp::Image

pub struct Image { /* 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[src]

pub fn new(width: u32, height: u32) -> Image[src]

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

Example

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

pub fn get_width(&self) -> u32[src]

Returns the width of the Image.

pub fn get_height(&self) -> u32[src]

Returns the height of the Image.

pub fn set_pixel(&mut self, x: u32, y: u32, val: Pixel)[src]

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

Example

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

pub fn get_pixel(&self, x: u32, y: u32) -> Pixel[src]

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

Example

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

Important traits for ImageIndex
pub fn coordinates(&self) -> ImageIndex[src]

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

Example

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

pub fn save<P: AsRef<Path>>(&self, path: P) -> Result<()>[src]

Saves the Image instance to the path specified by path. The function will overwrite the contents if a file already exists at the given path.

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

Example

use bmp::Image;

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

pub fn to_writer<W: Write>(&self, destination: &mut W) -> Result<()>[src]

Writes the Image instance to the writer referenced by destination.

Trait Implementations

impl Clone for Image[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl PartialEq<Image> for Image[src]

impl Eq for Image[src]

impl Debug for Image[src]

Auto Trait Implementations

impl Sync for Image

impl Send for Image

impl Unpin for Image

impl RefUnwindSafe for Image

impl UnwindSafe for Image

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]