Trait Bitmap

Source
pub trait Bitmap: Clone {
    // Required methods
    fn new(size: Size<i32>, color: Color) -> Self;
    fn size(&self) -> Size<i32>;
    fn width(&self) -> i32;
    fn height(&self) -> i32;
    fn pixel(&self, point: Point<i32>) -> Color;
    fn set_pixel(&mut self, point: Point<i32>, color: Color);
    fn bytes(&self) -> &[u8] ;
    fn from_parts(size: Size<i32>, bytes: &[u8]) -> Self;
    fn set_from(&mut self, other: &Self);

    // Provided methods
    fn png_bytes(&self) -> Result<Vec<u8>> { ... }
    fn try_from_file_bytes(bytes: Vec<u8>) -> Result<Self> { ... }
}
Expand description

Represents a 2D matrix of pixels (an image)

Required Methods§

Source

fn new(size: Size<i32>, color: Color) -> Self

Create a new image with a specified size and filled with one color

Source

fn size(&self) -> Size<i32>

Get the Size of the image

Source

fn width(&self) -> i32

Get the width of the image in pixels

Source

fn height(&self) -> i32

Get the height of the image in pixels

Source

fn pixel(&self, point: Point<i32>) -> Color

Get the pixel color at a certain Point

Source

fn set_pixel(&mut self, point: Point<i32>, color: Color)

Set the pixel at a certain Point to a specified color

Source

fn bytes(&self) -> &[u8]

Get this image’s representation as a slice of bytes

Source

fn from_parts(size: Size<i32>, bytes: &[u8]) -> Self

Create a new image from a slice of bytes and a Size

Source

fn set_from(&mut self, other: &Self)

Set this image pixels based on another, but respecting the size of this one, i.e. ignoring pixels out of bounds

Provided Methods§

Source

fn png_bytes(&self) -> Result<Vec<u8>>

Get the the PNG representation of this image as a sequence of bytes

Source

fn try_from_file_bytes(bytes: Vec<u8>) -> Result<Self>

Create a new image from a sequence of bytes read from an image file (e.g. PNG or JPG)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§