ImageRef

Type Alias ImageRef 

Source
pub type ImageRef<'a, Color> = Image<Color, &'a [Color]>;
Expand description

A borrowed image backed by a reference to a slice.

This type consists of a width, a height, and a pixel slice in row-major order. The length of the pixel slice is guaranteed to match width * height and be less than or equal to MAX_PIXELS.

See ImageBuf for an owned variant of an image and ImageMut for a mutable, borrowed image.

§Examples

Directly creating an ImageRef from a slice:

let (width, height) = (512, 512);
let pixels = vec![Srgb::new(0, 0, 0); (width * height) as usize];
let image = ImageRef::new(width, height, &pixels).unwrap();

Converting a reference to a RgbImage from the image crate to an ImageRef:

let image = RgbImage::new(256, 256);
let image = ImageRef::try_from(&image)?;

Aliased Type§

pub struct ImageRef<'a, Color> { /* private fields */ }

Trait Implementations§

Source§

impl<Color> Default for ImageRef<'_, Color>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a, Component, Container> TryFrom<&'a ImageBuffer<Rgb<Component>, Container>> for ImageRef<'a, Srgb<Component>>
where Rgb<Component>: Pixel<Subpixel = Component>, Container: Deref<Target = [<Rgb<Component> as Pixel>::Subpixel]>,

Source§

type Error = LengthOutOfRange

The type returned in the event of a conversion error.
Source§

fn try_from( image: &'a ImageBuffer<Rgb<Component>, Container>, ) -> Result<Self, Self::Error>

Performs the conversion.