[−][src]Struct embedded_graphics::image::ImageRaw
An image constructed from a slice of raw pixel data.
The ImageRaw
struct can be used to construct an image 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.
To draw an ImageRaw
object it needs to be wrapped in an Image
object.
Examples
Draw a 1BPP image
This example creates an image from 1 bit per pixel data.
use embedded_graphics::{ image::{Image, ImageRaw}, pixelcolor::BinaryColor, prelude::*, }; /// 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. #[rustfmt::skip] const DATA: &[u8] = &[ 0b11101111, 0b0101_0000, 0b10001000, 0b0101_0000, 0b11101011, 0b0101_0000, 0b10001001, 0b0101_0000, 0b11101111, 0b0101_0000, ]; // The type annotation `ImageRaw<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 raw_image: ImageRaw<BinaryColor> = ImageRaw::new(DATA, 12, 5); let image = Image::new(&raw_image, Point::zero()); let mut display = Display::default(); image.draw(&mut display)?;
Draw an image that uses multibyte pixel encoding
Colors with more than one byte per pixel need an additional type annotation for the byte order.
For convenience, the ImageRawBE
and ImageRawLE
type aliases can be used to abbreviate
the type.
use embedded_graphics::{ image::{Image, ImageRaw, ImageRawBE, ImageRawLE}, pixelcolor::{ raw::{BigEndian, LittleEndian}, Rgb565, Rgb888, }, prelude::*, }; // Rgb888 image with 24 bits per pixel and big endian byte order let image1: ImageRawBE<Rgb888> = ImageRaw::new(DATA, 8, 8); // or: let image2: ImageRaw<Rgb888, BigEndian> = ImageRaw::new(DATA, 8, 8); // Rgb565 image with 16 bits per pixel and little endian byte order let image1: ImageRawLE<Rgb565> = ImageRaw::new(DATA, 16, 6); // or: let image2: ImageRaw<Rgb565, LittleEndian> = ImageRaw::new(DATA, 16, 6);
Implementations
impl<'a, C, BO> ImageRaw<'a, C, BO> where
C: PixelColor + From<<C as PixelColor>::Raw>,
BO: ByteOrder,
[src]
C: PixelColor + From<<C as PixelColor>::Raw>,
BO: ByteOrder,
Trait Implementations
impl<'a, C: Clone, BO: Clone> Clone for ImageRaw<'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 clone(&self) -> ImageRaw<'a, C, BO>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'a, C: Copy, BO: Copy> Copy for ImageRaw<'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: Debug, BO: Debug> Debug for ImageRaw<'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: Eq, BO: Eq> Eq for ImageRaw<'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: Hash, BO: Hash> Hash for ImageRaw<'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 hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'a, C, BO> ImageDrawable for ImageRaw<'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>,
type Color = C
The color type.
pub fn draw<D>(&self, target: &mut D) -> Result<(), D::Error> where
D: DrawTarget<Color = C>,
[src]
D: DrawTarget<Color = C>,
pub fn draw_sub_image<D>(
&self,
target: &mut D,
area: &Rectangle
) -> Result<(), <D as DrawTarget>::Error> where
D: DrawTarget<Color = Self::Color>,
[src]
&self,
target: &mut D,
area: &Rectangle
) -> Result<(), <D as DrawTarget>::Error> where
D: DrawTarget<Color = Self::Color>,
impl<'a, C: Ord, BO: Ord> Ord for ImageRaw<'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 cmp(&self, other: &ImageRaw<'a, C, BO>) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<C, BO, '_> OriginDimensions for ImageRaw<'_, 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<ImageRaw<'a, C, BO>> for ImageRaw<'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 eq(&self, other: &ImageRaw<'a, C, BO>) -> bool
[src]
pub fn ne(&self, other: &ImageRaw<'a, C, BO>) -> bool
[src]
impl<'a, C: PartialOrd, BO: PartialOrd> PartialOrd<ImageRaw<'a, C, BO>> for ImageRaw<'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 partial_cmp(&self, other: &ImageRaw<'a, C, BO>) -> Option<Ordering>
[src]
pub fn lt(&self, other: &ImageRaw<'a, C, BO>) -> bool
[src]
pub fn le(&self, other: &ImageRaw<'a, C, BO>) -> bool
[src]
pub fn gt(&self, other: &ImageRaw<'a, C, BO>) -> bool
[src]
pub fn ge(&self, other: &ImageRaw<'a, C, BO>) -> bool
[src]
impl<'a, C, BO> StructuralEq for ImageRaw<'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> StructuralPartialEq for ImageRaw<'a, C, BO> where
C: PixelColor + From<<C as PixelColor>::Raw>,
BO: ByteOrder,
[src]
C: PixelColor + From<<C as PixelColor>::Raw>,
BO: ByteOrder,
Auto Trait Implementations
impl<'a, C, BO> RefUnwindSafe for ImageRaw<'a, C, BO> where
BO: RefUnwindSafe,
C: RefUnwindSafe,
BO: RefUnwindSafe,
C: RefUnwindSafe,
impl<'a, C, BO> Send for ImageRaw<'a, C, BO> where
BO: Send,
C: Send,
BO: Send,
C: Send,
impl<'a, C, BO> Sync for ImageRaw<'a, C, BO> where
BO: Sync,
C: Sync,
BO: Sync,
C: Sync,
impl<'a, C, BO> Unpin for ImageRaw<'a, C, BO> where
BO: Unpin,
C: Unpin,
BO: Unpin,
C: Unpin,
impl<'a, C, BO> UnwindSafe for ImageRaw<'a, C, BO> where
BO: UnwindSafe,
C: UnwindSafe,
BO: UnwindSafe,
C: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Dimensions for T where
T: OriginDimensions,
[src]
T: OriginDimensions,
pub fn bounding_box(&self) -> Rectangle
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<Src, Dst> LosslessTryInto<Dst> for Src where
Dst: LosslessTryFrom<Src>,
[src]
Dst: LosslessTryFrom<Src>,
pub fn lossless_try_into(self) -> Option<Dst>
[src]
impl<Src, Dst> LossyInto<Dst> for Src where
Dst: LossyFrom<Src>,
[src]
Dst: LossyFrom<Src>,
pub fn lossy_into(self) -> Dst
[src]
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> Scalar for T where
T: PartialEq<T> + Copy + Any + Debug,
[src]
T: PartialEq<T> + Copy + Any + Debug,
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
SS: SubsetOf<SP>,
pub fn to_subset(&self) -> Option<SS>
pub fn is_in_subset(&self) -> bool
pub fn to_subset_unchecked(&self) -> SS
pub fn from_subset(element: &SS) -> SP
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
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.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[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.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,