pub struct Image { /* private fields */ }
Expand description
Handle to an image stored in GPU memory.
Implementations§
source§impl Image
impl Image
sourcepub fn new_canvas_image(
gfx: &impl Has<GraphicsContext>,
format: ImageFormat,
width: u32,
height: u32,
samples: u32
) -> Self
pub fn new_canvas_image( gfx: &impl Has<GraphicsContext>, format: ImageFormat, width: u32, height: u32, samples: u32 ) -> Self
Creates a new image specifically for use with a Canvas.
sourcepub fn from_color(
gfx: &impl Has<GraphicsContext>,
width: u32,
height: u32,
color: Option<Color>
) -> Self
pub fn from_color( gfx: &impl Has<GraphicsContext>, width: u32, height: u32, color: Option<Color> ) -> Self
A little helper function that creates a blank Image
that is of the given width and height and optional color.
The default color is Color::WHITE
.
Mainly useful for debugging.
sourcepub fn from_pixels(
gfx: &impl Has<GraphicsContext>,
pixels: &[u8],
format: ImageFormat,
width: u32,
height: u32
) -> Self
pub fn from_pixels( gfx: &impl Has<GraphicsContext>, pixels: &[u8], format: ImageFormat, width: u32, height: u32 ) -> Self
Creates a new image initialized with given pixel data.
sourcepub fn from_path(
gfx: &impl Has<GraphicsContext>,
path: impl AsRef<Path>
) -> GameResult<Self>
pub fn from_path( gfx: &impl Has<GraphicsContext>, path: impl AsRef<Path> ) -> GameResult<Self>
Creates a new image initialized with pixel data loaded from a given path as an
encoded image Read
(e.g. PNG or JPEG).
sourcepub fn from_bytes(
gfx: &impl Has<GraphicsContext>,
encoded: &[u8]
) -> Result<Image, GameError>
pub fn from_bytes( gfx: &impl Has<GraphicsContext>, encoded: &[u8] ) -> Result<Image, GameError>
Creates a new image initialized with pixel data from a given encoded image (e.g. PNG or JPEG)
sourcepub fn wgpu(&self) -> (&Texture, &TextureView)
pub fn wgpu(&self) -> (&Texture, &TextureView)
Returns the underlying wgpu::Texture
and wgpu::TextureView
for this Image
.
sourcepub fn to_pixels(&self, gfx: &impl Has<GraphicsContext>) -> GameResult<Vec<u8>>
pub fn to_pixels(&self, gfx: &impl Has<GraphicsContext>) -> GameResult<Vec<u8>>
Reads the pixels of this ImageView
and returns as Vec<u8>
.
The format matches the GPU image format.
This is a very expensive operation - call sparingly.
sourcepub fn encode(
&self,
ctx: &Context,
format: ImageEncodingFormat,
path: impl AsRef<Path>
) -> GameResult
pub fn encode( &self, ctx: &Context, format: ImageEncodingFormat, path: impl AsRef<Path> ) -> GameResult
Encodes the ImageView
to the given file format and return the encoded bytes.
This is a very expensive operation - call sparingly.
sourcepub fn format(&self) -> ImageFormat
pub fn format(&self) -> ImageFormat
Returns the image format of this image.