Struct druid::ImageBuf

pub struct ImageBuf { /* private fields */ }
Expand description

An in-memory pixel buffer.

Contains raw bytes, dimensions, and image format (ImageFormat).

Implementations§

§

impl ImageBuf

pub fn empty() -> ImageBuf

Create an empty image buffer.

pub fn from_raw( pixels: impl Into<Arc<[u8]>>, format: ImageFormat, width: usize, height: usize ) -> ImageBuf

Creates a new image buffer from an array of bytes.

format specifies the pixel format of the pixel data, which must have length width * height * format.bytes_per_pixel().

Panics

Panics if the pixel data has the wrong length.

pub fn raw_pixels(&self) -> &[u8]

Returns the raw pixel data of this image buffer.

pub fn raw_pixels_shared(&self) -> Arc<[u8]>

Returns a shared reference to the raw pixel data of this image buffer.

pub fn format(&self) -> ImageFormat

Returns the format of the raw pixel data.

pub fn width(&self) -> usize

The width, in pixels, of this image.

pub fn height(&self) -> usize

The height, in pixels, of this image.

pub fn size(&self) -> Size

The size of this image, in pixels.

pub fn pixel_colors(&self) -> impl Iterator<Item = impl Iterator<Item = Color>>

Returns an iterator over the pixels in this image.

The return value is an iterator over “rows”, where each “row” is an iterator over the color of the pixels in that row.

pub fn to_image<Ctx>(&self, ctx: &mut Ctx) -> <Ctx as RenderContext>::Imagewhere Ctx: RenderContext,

Converts this buffer an image that is optimized for drawing into a RenderContext.

pub fn ptr_eq(&self, other: &ImageBuf) -> bool

Returns true if the two ImageBufs refer to the same memory location.

§

impl ImageBuf

pub fn from_dynamic_image(image_data: DynamicImage) -> ImageBuf

Load an image from a DynamicImage from the image crate

pub fn from_dynamic_image_with_alpha(image_data: DynamicImage) -> ImageBuf

Load an image from a DynamicImage with alpha

pub fn from_dynamic_image_without_alpha(image_data: DynamicImage) -> ImageBuf

Load an image from a DynamicImage without alpha

pub fn from_data( raw_image: &[u8] ) -> Result<ImageBuf, Box<dyn Error + Sync + Send + 'static, Global>>

Attempt to load an image from raw bytes.

If the image crate can’t decode an image from the data an error will be returned.

pub fn from_file<P>( path: P ) -> Result<ImageBuf, Box<dyn Error + Sync + Send + 'static, Global>>where P: AsRef<Path>,

Attempt to load an image from the file at the provided path.

Trait Implementations§

§

impl Clone for ImageBuf

§

fn clone(&self) -> ImageBuf

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Data for ImageBuf

source§

fn same(&self, other: &Self) -> bool

Determine whether two values are the same. Read more
§

impl Debug for ImageBuf

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for ImageBuf

§

fn default() -> ImageBuf

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

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> RoundFrom<T> for T

§

fn round_from(x: T) -> T

Performs the conversion.
§

impl<T, U> RoundInto<U> for Twhere U: RoundFrom<T>,

§

fn round_into(self) -> U

Performs the conversion.
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more