Struct ggez::graphics::Image

source ·
pub struct Image { /* private fields */ }
Expand description

Handle to an image stored in GPU memory.

Implementations§

source§

impl Image

source

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.

source

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.

source

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.

source

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).

source

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)

source

pub fn wgpu(&self) -> (&Texture, &TextureView)

Returns the underlying wgpu::Texture and wgpu::TextureView for this Image.

source

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.

source

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.

source

pub fn format(&self) -> ImageFormat

Returns the image format of this image.

source

pub fn samples(&self) -> u32

Returns the number of MSAA samples this image has.

source

pub fn width(&self) -> u32

Returns the width (in pixels) of the image.

source

pub fn height(&self) -> u32

Returns the height (in pixels) of the image.

source

pub fn uv_rect(&self, x: u32, y: u32, w: u32, h: u32) -> Rect

Helper function that calculates a sub-rectangle of this image in UV coordinates, given pixel coordinates.

Trait Implementations§

source§

impl Clone for Image

source§

fn clone(&self) -> Image

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Image

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drawable for Image

source§

fn draw(&self, canvas: &mut Canvas, param: impl Into<DrawParam>)

Draws the drawable onto the canvas.
source§

fn dimensions(&self, _gfx: &impl Has<GraphicsContext>) -> Option<Rect>

Returns a bounding box in the form of a Rect. Read more

Auto Trait Implementations§

§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

source§

impl<T> Has<T> for T

source§

fn retrieve(&self) -> &T

Method to retrieve the context type.
source§

impl<T> HasMut<T> for T

source§

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

Method to retrieve the context type as mutable.
source§

impl<T, U> Into<U> for Twhere 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.

§

impl<F, T> IntoSample<T> for Fwhere T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> ToSample<U> for Twhere U: FromSample<T>,

§

fn to_sample_(self) -> U

source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<S, T> Duplex<S> for Twhere T: FromSample<S> + ToSample<S>,