[−][src]Struct embedded_graphics::image::Image
An image constructed from a slice.
The Image
struct can be used to construct an image drawable from a slice
of raw image data. The storage format is determined by the PixelColor
type C
and the ByteOrder
BO
. The byteorder doesn't need to be
specified for colors which aren't stored in multiple bytes.
For color types with less than 8 bits per pixels the start of each row is aligned to the next whole byte.
Details about the conversion of raw data to color types are explained in the
raw
module documentation.
Examples
This example creates an image from 1 bit per pixel data:
use embedded_graphics::prelude::*; use embedded_graphics::pixelcolor::BinaryColor; /// Image data with 12 x 5 pixels. /// The data for each row is 12 bits long and is padded with zeros on the /// end because each row needs to contain a whole number of bytes. const DATA: &[u8] = &[ 0b11101111, 0b0101_0000, 0b10001000, 0b0101_0000, 0b11101011, 0b0101_0000, 0b10001001, 0b0101_0000, 0b11101111, 0b0101_0000, ]; fn main() { // The type annotation `Image<BinaryColor>` is used to specify the format // of the stored raw data (`PixelColor::Raw`) and which color type the // raw data gets converted into. let image: Image<BinaryColor> = Image::new(DATA, 12, 5); let mut display = Display::default(); display.draw(&image); }
Colors with more than one byte per pixel need an additional type annotation
for the byte order. The ImageBE
and ImageLE
type aliases can be used
to abbreviate the type.
use embedded_graphics::prelude::*; use embedded_graphics::image::{ImageLE, ImageBE}; use embedded_graphics::pixelcolor::{Rgb565, Rgb888}; use embedded_graphics::pixelcolor::raw::{BigEndian, LittleEndian}; // Rgb888 image with 24 bits per pixel and big endian byte order let image1: ImageBE<Rgb888> = Image::new(DATA, 8, 8); // or: let image2: Image<Rgb888, BigEndian> = Image::new(DATA, 8, 8); // Rgb565 image with 16 bits per pixel and little endian byte order let image1: ImageLE<Rgb565> = Image::new(DATA, 16, 6); // or: let image2: Image<Rgb565, LittleEndian> = Image::new(DATA, 16, 6);
Methods
impl<'a, C, BO> Image<'a, C, BO> where
C: PixelColor + From<<C as PixelColor>::Raw>,
BO: ByteOrder,
[src]
C: PixelColor + From<<C as PixelColor>::Raw>,
BO: ByteOrder,
pub fn new(data: &'a [u8], width: u32, height: u32) -> Self
[src]
pub fn offset(&self) -> Point
[src]
Returns the offset.
Trait Implementations
impl<'a, C, BO> Drawable for Image<'a, C, BO> where
C: PixelColor + From<<C as PixelColor>::Raw>,
BO: ByteOrder,
[src]
C: PixelColor + From<<C as PixelColor>::Raw>,
BO: ByteOrder,
impl<'a, C, BO> Dimensions for Image<'a, C, BO> where
C: PixelColor + From<<C as PixelColor>::Raw>,
BO: ByteOrder,
[src]
C: PixelColor + From<<C as PixelColor>::Raw>,
BO: ByteOrder,
impl<'a, C, BO> Transform for Image<'a, C, BO> where
C: PixelColor + From<<C as PixelColor>::Raw>,
BO: ByteOrder,
[src]
C: PixelColor + From<<C as PixelColor>::Raw>,
BO: ByteOrder,
fn translate(&self, by: Point) -> Self
[src]
Translate the image from its current position to a new position by (x, y) pixels, returning
a new Image
. For a mutating transform, see translate_mut
.
// 8px x 1px test image let image: Image<BinaryColor> = Image::new(&[ 0xff ], 8, 1); let moved = image.translate(Point::new(25, 30)); assert_eq!(image.offset(), Point::new(0, 0)); assert_eq!(moved.offset(), Point::new(25, 30));
fn translate_mut(&mut self, by: Point) -> &mut Self
[src]
Translate the image from its current position to a new position by (x, y) pixels.
let mut image: Image<BinaryColor> = Image::new(&[ 0xff ], 8, 1); image.translate_mut(Point::new(25, 30)); assert_eq!(image.offset(), Point::new(25, 30));
impl<'a, C: Debug, BO: Debug> Debug for Image<'a, C, BO> where
C: PixelColor + From<<C as PixelColor>::Raw>,
BO: ByteOrder,
[src]
C: PixelColor + From<<C as PixelColor>::Raw>,
BO: ByteOrder,
impl<'a, C: PartialEq, BO: PartialEq> PartialEq<Image<'a, C, BO>> for Image<'a, C, BO> where
C: PixelColor + From<<C as PixelColor>::Raw>,
BO: ByteOrder,
[src]
C: PixelColor + From<<C as PixelColor>::Raw>,
BO: ByteOrder,
fn eq(&self, other: &Image<'a, C, BO>) -> bool
[src]
fn ne(&self, other: &Image<'a, C, BO>) -> bool
[src]
impl<'a, C: Eq, BO: Eq> Eq for Image<'a, C, BO> where
C: PixelColor + From<<C as PixelColor>::Raw>,
BO: ByteOrder,
[src]
C: PixelColor + From<<C as PixelColor>::Raw>,
BO: ByteOrder,
impl<'a, C, BO> IntoIterator for &'a Image<'a, C, BO> where
C: PixelColor + From<<C as PixelColor>::Raw>,
BO: ByteOrder,
RawDataIter<'a, C::Raw, BO>: Iterator<Item = C::Raw>,
[src]
C: PixelColor + From<<C as PixelColor>::Raw>,
BO: ByteOrder,
RawDataIter<'a, C::Raw, BO>: Iterator<Item = C::Raw>,
Auto Trait Implementations
impl<'a, C, BO> Unpin for Image<'a, C, BO> where
BO: Unpin,
C: Unpin,
BO: Unpin,
C: Unpin,
impl<'a, C, BO> Sync for Image<'a, C, BO> where
BO: Sync,
C: Sync,
BO: Sync,
C: Sync,
impl<'a, C, BO> Send for Image<'a, C, BO> where
BO: Send,
C: Send,
BO: Send,
C: Send,
Blanket Implementations
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
SS: SubsetOf<SP>,