Struct Image

Source
pub struct Image { /* private fields */ }
Expand description

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.

Implementations§

Source§

impl Image

Source

pub 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
let mut img = bmp::Image::new(100, 80);
Source

pub fn get_width(&self) -> u32

Returns the width of the Image.

Source

pub fn get_height(&self) -> u32

Returns the height of the Image.

Source

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

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

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

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

pub fn coordinates(&self) -> ImageIndex

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

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

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

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

Writes the Image instance to the writer referenced by destination.

Trait Implementations§

Source§

impl Clone for Image

Source§

fn clone(&self) -> Image

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Image

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Image

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Image

Source§

impl StructuralPartialEq for Image

Auto Trait Implementations§

§

impl Freeze for Image

§

impl RefUnwindSafe for Image

§

impl Send for Image

§

impl Sync for Image

§

impl Unpin for Image

§

impl UnwindSafe for Image

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.