pub struct Image {
pub width: u32,
pub height: u32,
pub data: Vec<u8>,
pub filter_type: FilterType,
}Expand description
§Image
Contains pixel data for a width * height image in RGBA format.
Data is stored as 4 * w * h 8-bit r, g, b, a values.
Fields§
§width: u32§height: u32§data: Vec<u8>§filter_type: FilterTypeImplementations§
Source§impl Image
impl Image
Sourcepub fn new(width: u32, height: u32, filter_type: FilterType) -> Self
pub fn new(width: u32, height: u32, filter_type: FilterType) -> Self
Creates a new black/transparent image filled with zeros (RGBA 8-bit).
Sourcepub fn from_data(
width: u32,
height: u32,
filter_type: FilterType,
data: Vec<u8>,
) -> Self
pub fn from_data( width: u32, height: u32, filter_type: FilterType, data: Vec<u8>, ) -> Self
Wraps an existing Vec
Sourcepub fn from_pixels(
width: u32,
height: u32,
filter_type: FilterType,
pixels: Vec<Color>,
) -> Self
pub fn from_pixels( width: u32, height: u32, filter_type: FilterType, pixels: Vec<Color>, ) -> Self
Creates an image from a collection of Colors.
Color channels are expected to be normalized to [0.0, 1.0] and are converted to 8-bit [0, 255] values.
Sourcepub fn with_filter_type(self, filter_type: FilterType) -> Self
pub fn with_filter_type(self, filter_type: FilterType) -> Self
Returns image with filter type.
Sourcepub fn set_pixel(&mut self, x: u32, y: u32, color: Color)
pub fn set_pixel(&mut self, x: u32, y: u32, color: Color)
Sets the RGBA color [r, g, b, a] for pixel at (x, y).
Color channels are expected to be normalized to [0.0, 1.0].
Sourcepub fn get_pixel(&self, x: u32, y: u32) -> Option<Color>
pub fn get_pixel(&self, x: u32, y: u32) -> Option<Color>
Gets the RGBA color [r, g, b, a] at (x, y). Returns None if out of bounds.
Color channels are returned normalized to [0.0, 1.0].
Sourcepub fn clear(&mut self, color: [f32; 4])
pub fn clear(&mut self, color: [f32; 4])
Clears the image using a single RGBA color.
Color channels are expected to be normalized to [0.0, 1.0].
Sourcepub fn to_dynamic(&self) -> DynamicImage
pub fn to_dynamic(&self) -> DynamicImage
Converts this struct directly into image::DynamicImage.
Sourcepub fn from_dynamic(dynamic: &DynamicImage, filter_type: FilterType) -> Self
pub fn from_dynamic(dynamic: &DynamicImage, filter_type: FilterType) -> Self
Creates an Image from an image::DynamicImage.
Pixel data is stored directly as normalized 8-bit RGBA.
Sourcepub fn to_rgba8_buffer(&self) -> RgbaImage
pub fn to_rgba8_buffer(&self) -> RgbaImage
Converts this image to an 8-bit RGBA ImageBuffer.
This clones the underlying data because the returned ImageBuffer owns it.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Image
impl RefUnwindSafe for Image
impl Send for Image
impl Sync for Image
impl Unpin for Image
impl UnsafeUnpin for Image
impl UnwindSafe for Image
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more