Bitmap

Struct Bitmap 

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

A bitmap image.

The bitmap can be cloned which will make a clone of the pixels as well. The bitmap’s pixels data is freed when the bitmap is dropped.

An Bitmap is borrowed as an &BitmapRef and all methods of that type are available for `Bitmap as well.

Implementations§

Source§

impl Bitmap

Source

pub fn new<'a, C: Into<Color<'a>>>( width: i32, height: i32, bg_color: C, ) -> Bitmap

Allocates and returns a new Bitmap with pixel dimentions of width by height. The bitmap’s pixels will be initialized to bg_color.

Source

pub fn from_bitmap_with_rotation( bitmap: &BitmapRef, rotation: f32, xscale: f32, yscale: f32, ) -> Bitmap

Returns a new, rotated and scaled Bitmap based on the given bitmap.

Source

pub fn from_file(path: &str) -> Result<Bitmap, Error>

Methods from Deref<Target = BitmapRef>§

Source

pub fn load_file(&mut self, path: &str) -> Result<(), Error>

Loads the image at path into the previously allocated BitmapRef.

Source

pub fn data(&self) -> BitmapData

Returns the bitmap’s metadata such as its width and height.

Source

pub fn as_bytes(&self) -> &[u8]

Gives read acccess to the pixels of the bitmap as an array of bytes.

Each byte represents 8 pixels, where each pixel is a bit. The highest bit is the leftmost pixel, and lowest bit is the rightmost. There are Bitmap::data().rowbytes many bytes in each row, regardless of the number of pixels in a row, which can introduce padding bytes between rows. For this reason, the Bitmap::as_pixels() method is recommended, and easier to use.

Source

pub fn as_mut_bytes(&mut self) -> &mut [u8]

Gives read-write acccess to the pixels of the bitmap as an array of bytes.

Each byte represents 8 pixels, where each pixel is a bit. The highest bit is the leftmost pixel, and lowest bit is the rightmost. There are Bitmap::data().rowbytes many bytes in each row, regardless of the number of pixels in a row, which can introduce padding bytes between rows. For this reason, the Bitmap::as_pixels_mit() method is recommended, and easier to use.

Source

pub fn as_pixels(&self) -> BitmapPixels<'_>

Gives read acccess to the individual pixels of the bitmap.

Source

pub fn as_pixels_mut(&mut self) -> BitmapPixelsMut<'_>

Gives read-write acccess to the individual pixels of the bitmap.

Source

pub fn clear<'a, C: Into<Color<'a>>>(&mut self, bg_color: C)

Clears the bitmap, filling with the given bg_color.

Source

pub fn set_mask_bitmap(&mut self, mask: &BitmapRef) -> Result<(), Error>

Sets a mask image for the given bitmap. The set mask must be the same size as the target bitmap.

The mask bitmap is copied, so no reference is held to it. Returns an Error::DimensionsDoNotMatch if the mask bitmap dimensions do not match with self.

Source

pub fn mask_bitmap(&self) -> Option<UnownedBitmapMut<'_>>

The mask bitmap attached to this bitmap.

Returns the mask bitmap, if one has been attached with set_mask_bitmap(), or None.

Trait Implementations§

Source§

impl AsMut<BitmapRef> for Bitmap

Source§

fn as_mut(&mut self) -> &mut BitmapRef

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<BitmapRef> for Bitmap

Source§

fn as_ref(&self) -> &BitmapRef

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<BitmapRef> for Bitmap

Source§

fn borrow(&self) -> &BitmapRef

Immutably borrows from an owned value. Read more
Source§

impl BorrowMut<BitmapRef> for Bitmap

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl Clone for Bitmap

Source§

fn clone(&self) -> Self

Clones the Bitmap which includes making a copy of all its pixels.

1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Bitmap

Source§

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

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

impl Deref for Bitmap

Source§

type Target = BitmapRef

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for Bitmap

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl Drop for Bitmap

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Bitmap

§

impl RefUnwindSafe for Bitmap

§

impl !Send for Bitmap

§

impl !Sync for Bitmap

§

impl Unpin for Bitmap

§

impl UnwindSafe for Bitmap

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.