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
impl Bitmap
Sourcepub fn new<'a, C: Into<Color<'a>>>(
width: i32,
height: i32,
bg_color: C,
) -> Bitmap
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
.
Sourcepub fn from_bitmap_with_rotation(
bitmap: &BitmapRef,
rotation: f32,
xscale: f32,
yscale: f32,
) -> Bitmap
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
.
pub fn from_file(path: &str) -> Result<Bitmap, Error>
Methods from Deref<Target = BitmapRef>§
Sourcepub fn load_file(&mut self, path: &str) -> Result<(), Error>
pub fn load_file(&mut self, path: &str) -> Result<(), Error>
Loads the image at path
into the previously allocated BitmapRef
.
Sourcepub fn data(&self) -> BitmapData
pub fn data(&self) -> BitmapData
Returns the bitmap’s metadata such as its width and height.
Sourcepub fn as_bytes(&self) -> &[u8]
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.
Sourcepub fn as_mut_bytes(&mut self) -> &mut [u8]
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.
Sourcepub fn as_pixels(&self) -> BitmapPixels<'_>
pub fn as_pixels(&self) -> BitmapPixels<'_>
Gives read acccess to the individual pixels of the bitmap.
Sourcepub fn as_pixels_mut(&mut self) -> BitmapPixelsMut<'_>
pub fn as_pixels_mut(&mut self) -> BitmapPixelsMut<'_>
Gives read-write acccess to the individual pixels of the bitmap.
Sourcepub fn clear<'a, C: Into<Color<'a>>>(&mut self, bg_color: C)
pub fn clear<'a, C: Into<Color<'a>>>(&mut self, bg_color: C)
Clears the bitmap, filling with the given bg_color
.
Sourcepub fn set_mask_bitmap(&mut self, mask: &BitmapRef) -> Result<(), Error>
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
.
Sourcepub fn mask_bitmap(&self) -> Option<UnownedBitmapMut<'_>>
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.