Struct Bitmap

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

A rectangular 2d-array of u8 where the values 0 through 255 represent shades of grey.

Implementations§

Source§

impl Bitmap

Source

pub fn lines(&self) -> Chunks<'_, u8>

Return an iterator over the lines of the bitmap going from top to bottom.

Examples found in repository?
examples/basic_char.rs (line 8)
4fn main() {
5    let bytes = include_bytes!("Gudea-Regular.ttf");
6    let font = load_font_from_bytes(bytes.to_vec());
7    let (_, bitmap) = font.render_char('A', 40.0).unwrap();
8    for line in bitmap.lines() {
9        for &pixel in line {
10            if pixel == 0 {
11                print!(" ");
12            } else {
13                print!("#");
14            }
15        }
16        println!("");
17    }
18}
More examples
Hide additional examples
examples/basic_atlas.rs (line 9)
4fn main() {
5    let bytes = include_bytes!("Gudea-Regular.ttf");
6    let font = load_font_from_bytes(bytes.to_vec());
7    let chars = font_atlas::ASCII.iter().cloned().chain(font_atlas::ASCII.iter().cloned());
8    let (_, bitmap, _) = font.make_atlas(chars, 20.0, 1, 128, 128);
9    for line in bitmap.lines() {
10        print!("{:03} ", line.len());
11        for &pixel in line {
12            if pixel == 0 {
13                print!(" ");
14            } else {
15                print!("#");
16            }
17        }
18        println!("");
19    }
20}
Source

pub fn width(&self) -> usize

The width of this bitmap

Source

pub fn height(&self) -> usize

The height of this bitmap

Source

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

Gain access to the underlying slice of u8.

Source

pub fn into_raw(self) -> Vec<u8>

Get the underlying buffer of u8

Trait Implementations§

Source§

impl Buffer2d for Bitmap

Source§

type Pixel = u8

Source§

fn width(&self) -> u32

Source§

fn height(&self) -> u32

Source§

fn get(&self, x: u32, y: u32) -> Option<Self::Pixel>

Source§

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

Source§

fn patch<B: Buffer2d<Pixel = Self::Pixel>>(&mut self, x: u32, y: u32, buf: &B)

Source§

fn patch_rotated<B: Buffer2d<Pixel = Self::Pixel>>( &mut self, x: u32, y: u32, buf: &B, )

Source§

fn dimensions(&self) -> (u32, u32)

Source§

impl Debug for Bitmap

Source§

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

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

impl ResizeBuffer for Bitmap

Source§

fn resize(&mut self, width: u32, height: u32)

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> 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, 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.