Image

Struct Image 

Source
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,

Source

pub fn pixels(&self) -> PixelIter<'_, P>

Source

pub fn pixels_mut(&mut self) -> PixelIterMut<'_, P>

Source

pub fn par_pixels(&self) -> Iter<'_, P>

Source

pub fn par_pixels_mut(&mut self) -> IterMut<'_, P>

Source§

impl<P> Image<P>
where P: Pixel,

Source

pub fn new(width: usize, height: usize) -> Self

Creates a new empty Image instance with the specified width and height.

Source

pub fn open<Pth: AsRef<Path>>(path: Pth) -> Result<Self>

Creates a new Image instance from the given path.

Source

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.

Source

pub fn display(&self, title: &str) -> Result<()>

Opens an Image instance and displays it in a window.

Source

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.

Source

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.

Source

pub fn draw<D: Drawable<P>>(&mut self, shape: D) -> Result<()>

Draws a shape on the image. The shape must implement the Drawable trait.

Source

pub fn dimensions(&self) -> (usize, usize)

Returns the dimensions of the image as a tuple (width, height).

Source

pub fn is_empty(&self) -> bool

Returns true if the image is empty

Source

pub fn to_rgba8(&self) -> Image<Rgba<u8>>

Convert the image to RGBA8 format.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.