pub struct Image { /* private fields */ }Expand description
A struct that provides image handling functionality
§Examples
// Open and display an image
use glance_core::img::Image;
if let Ok(img) = Image::open("path/to/image.jpg") {
let _ = img.display("Example Image");
}Implementations§
Source§impl Image
impl Image
pub fn pixels(&self) -> PixelIter<'_> ⓘ
pub fn pixels_mut(&mut self) -> PixelIterMut<'_> ⓘ
pub fn par_pixels( &self, ) -> impl ParallelIterator<Item = (usize, usize, [u8; 4])>
pub fn par_pixels_mut( &mut self, ) -> impl ParallelIterator<Item = (usize, usize, &mut [u8; 4])>
Source§impl Image
impl Image
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
Opens an image from the given path.
Returns an error if the file does not exist or cannot be decoded.
Supports all formats recognized by the image crate.
Sourcepub fn save<P: AsRef<Path>>(&self, path: P) -> Result<()>
pub fn save<P: AsRef<Path>>(&self, path: P) -> Result<()>
Saves an image to the given path
Returns an error if the file cannot be created or buffer is invalid.
Format is recognized from file extension (see image::ImageBuffer::save for more info).
Sourcepub fn new(width: u32, height: u32, data: Vec<u8>) -> Result<Self>
pub fn new(width: u32, height: u32, data: Vec<u8>) -> Result<Self>
Creates a new Image from width, height, and a data buffer (must be RGBA, widthheight4 bytes).
Sourcepub fn display(&self, title: &str) -> Result<()>
pub fn display(&self, title: &str) -> Result<()>
Displays the image (as RGBA8) in a window until Escape is pressed.
Returns an error if the window cannot be created.
The window runs at 1 FPS to minimize CPU usage.
Uses minifb for cross-platform windowing.
Sourcepub fn get_pixel(&self, position: [u32; 2]) -> Result<[u8; 4]>
pub fn get_pixel(&self, position: [u32; 2]) -> Result<[u8; 4]>
Gets the color of a pixel. Top left is treated as origin. Right is positive x, down is positive y.
Sourcepub fn set_pixel(&mut self, position: [u32; 2], color: [u8; 4]) -> Result<()>
pub fn set_pixel(&mut self, position: [u32; 2], color: [u8; 4]) -> Result<()>
Sets a pixel to the given color. Top left is treated as origin, x-axis goes horizontally.
Sourcepub fn alpha_blend_pixel(
&mut self,
position: [u32; 2],
color: [u8; 4],
) -> Result<()>
pub fn alpha_blend_pixel( &mut self, position: [u32; 2], color: [u8; 4], ) -> Result<()>
Linearly interpolate a pixel color with the given color
Sourcepub fn draw<D: Drawable>(&mut self, shape: D) -> Result<()>
pub fn draw<D: Drawable>(&mut self, shape: D) -> Result<()>
Draw a shape (any struct that implements the [drawing::traits::Drawable] trait)
Sourcepub fn dimensions(&self) -> [u32; 2]
pub fn dimensions(&self) -> [u32; 2]
Returns the image dimensions as (width, height).
Auto Trait Implementations§
impl Freeze for Image
impl RefUnwindSafe for Image
impl Send for Image
impl Sync for Image
impl Unpin 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
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