pub struct ImageData<'a> { /* private fields */ }
Expand description
The image data representing the pixel data of an image.
Each pixel is represented by 4 bytes in RGBA (Red, Green, Blue, Alpha) format. The pixel data is stored in a linear array of bytes, where each pixel is represented by 4 bytes.
ยงExample
#[cfg(feature = "image")]
{
use auto_palette::ImageData;
let pixels = [
255, 0, 0, 255, // Red
0, 255, 0, 255, // Green
0, 0, 255, 255, // Blue
0, 0, 0, 255, // Black
];
let image_data = ImageData::new(2, 2, &pixels).unwrap();
assert_eq!(image_data.width(), 2);
assert_eq!(image_data.height(), 2);
assert_eq!(image_data.data(), &pixels);
}
Implementationsยง
Sourceยงimpl<'a> ImageData<'a>
impl<'a> ImageData<'a>
Sourcepub fn new(width: u32, height: u32, data: &'a [u8]) -> ImageResult<Self>
pub fn new(width: u32, height: u32, data: &'a [u8]) -> ImageResult<Self>
Creates a new ImageData
with the given width, height, and pixel data.
ยงArguments
width
- The width of the image data.height
- The height of the image data.data
- The pixel data of the image data.
ยงReturns
The ImageData
with the given width, height, and pixel data.
ยงErrors
Returns an error if the length of the pixel data is not equal to width * height * 4
.
Sourcepub fn load<P>(path: P) -> ImageResult<Self>
pub fn load<P>(path: P) -> ImageResult<Self>
Loads the image data from the given path.
The image data is loaded using the image
crate.
ยงArguments
path
- The path to the image file.
ยงReturns
The image data loaded from the given path.
ยงErrors
Returns an error if the image loading process fails. Returns an error if the color type of the image is not supported.
Trait Implementationsยง
Sourceยงimpl TryFrom<&DynamicImage> for ImageData<'_>
impl TryFrom<&DynamicImage> for ImageData<'_>
Sourceยงtype Error = ImageError
type Error = ImageError
The type returned in the event of a conversion error.
Auto Trait Implementationsยง
impl<'a> Freeze for ImageData<'a>
impl<'a> RefUnwindSafe for ImageData<'a>
impl<'a> Send for ImageData<'a>
impl<'a> Sync for ImageData<'a>
impl<'a> Unpin for ImageData<'a>
impl<'a> UnwindSafe for ImageData<'a>
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
Mutably borrows from an owned value. Read more