pub struct ImageRaw<'a, C, BO = BigEndian>{ }
Expand description
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.
This example creates an image from 1 bit per pixel data.
use embedded_graphics::{
image::{Image, ImageRaw},
pixelcolor::BinaryColor,
prelude::*,
};
#[rustfmt::skip]
const DATA: &[u8] = &[
0b11101111, 0b0101_0000,
0b10001000, 0b0101_0000,
0b11101011, 0b0101_0000,
0b10001001, 0b0101_0000,
0b11101111, 0b0101_0000,
];
let raw_image = ImageRaw::<BinaryColor>::new(DATA, 12);
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::*,
};
let image1 = ImageRawBE::<Rgb888>::new(DATA, 8);
let image2 = ImageRaw::<Rgb888, BigEndian>::new(DATA, 8);
let image1 = ImageRawLE::<Rgb565>::new(DATA, 16);
let image2 = ImageRaw::<Rgb565, LittleEndian>::new(DATA, 16);
Source§ Source
Creates a new image.
Only the width of the image needs to be specified. The height of the image will be calculated based on the length of the given image data. If the length of the image data isn’t an integer multiple of the data length for a single row the last partial row will be ignored.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4