pub struct Image<P: Pixel> { /* private fields */ }Expand description
Image struct represents an image with pixel data of type P
where P implements the Pixel trait.
Implementations§
Source§impl<P> Image<P>where
P: Pixel,
impl<P> Image<P>where
P: Pixel,
pub fn pixels(&self) -> PixelIter<'_, P> ⓘ
pub fn pixels_mut(&mut self) -> PixelIterMut<'_, P> ⓘ
pub fn par_pixels(&self) -> Iter<'_, P>
pub fn par_pixels_mut(&mut self) -> IterMut<'_, P>
Source§impl<P> Image<P>where
P: Pixel,
impl<P> Image<P>where
P: Pixel,
Sourcepub fn new(width: usize, height: usize) -> Self
pub fn new(width: usize, height: usize) -> Self
Creates a new empty Image instance with the specified width and height.
Sourcepub fn open<Pth: AsRef<Path>>(path: Pth) -> Result<Self>
pub fn open<Pth: AsRef<Path>>(path: Pth) -> Result<Self>
Creates a new Image instance from the given path.
Sourcepub fn save<Pth: AsRef<Path>>(&self, path: Pth) -> Result<()>
pub fn save<Pth: AsRef<Path>>(&self, path: Pth) -> Result<()>
Saves the image to the specified path. File format is determined by the file extension.
See image::ImageBuffer::save for more details.
Sourcepub fn display(&self, title: &str) -> Result<()>
pub fn display(&self, title: &str) -> Result<()>
Opens an Image instance and displays it in a window.
Sourcepub fn get_pixel(&self, position: (usize, usize)) -> Result<&P>
pub fn get_pixel(&self, position: (usize, usize)) -> Result<&P>
Returns a reference to the pixel data at the specified position. Returns an error if the position is out of bounds.
Sourcepub fn set_pixel(&mut self, position: (usize, usize), color: P) -> Result<()>
pub fn set_pixel(&mut self, position: (usize, usize), color: P) -> Result<()>
Sets the pixel at the specified position to the given color.
Colors are of type P, which implements the Pixel trait.
Returns an error if the position is out of bounds.
Sourcepub fn draw<D: Drawable<P>>(&mut self, shape: D) -> Result<()>
pub fn draw<D: Drawable<P>>(&mut self, shape: D) -> Result<()>
Draws a shape on the image. The shape must implement the Drawable trait.
Sourcepub fn dimensions(&self) -> (usize, usize)
pub fn dimensions(&self) -> (usize, usize)
Returns the dimensions of the image as a tuple (width, height).
Auto Trait Implementations§
impl<P> Freeze for Image<P>
impl<P> RefUnwindSafe for Image<P>where
P: RefUnwindSafe,
impl<P> Send for Image<P>
impl<P> Sync for Image<P>
impl<P> Unpin for Image<P>where
P: Unpin,
impl<P> UnwindSafe for Image<P>where
P: UnwindSafe,
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
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