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

An Image representing a buffer of pixel color values.

Implementations

Constructs an empty RGBA Image with given width and height.

Constructs an empty RGBA Image with given width and height.

Alias for Image::new.

Constructs an empty RGB Image with given width and height.

Constructs an Image from a u8 slice representing RGB/A values.

Errors

If the bytes length doesn’t match the image dimensions and PixelFormat provided, then an error is returned.

Constructs an Image from a Color slice representing RGBA values.

Errors

If the pixels length doesn’t match the image dimensions and PixelFormat provided, then an error is returned.

Constructs an Image from a Vec<u8> representing RGB/A values.

Constructs an Image from a png file.

Errors

If the file format is not supported or extension is not .png, then an error is returned.

Constructs an Image from a png reader.

Errors

If the file format is not supported or there is an io::Error reading the file then an error is returned.

Returns the Image width.

Returns the Image height.

Returns the Image dimensions as (width, height).

Returns the pitch of the image data which is the number of bytes in a row of pixel data, including padding between lines.

Returns the Image bounding Rect positioned at (0, 0).

The width and height of the returned rectangle are clamped to ensure that size does not exceed i32::MAX. This could result in unexpected behavior with drawing routines if the image size is larger than this.

Returns the Image bounding Rect positioned at offset.

Returns the center position as Point.

Returns the Image pixel data as an iterator of u8.

Returns the Image pixel data as a u8 slice.

Returns the Image pixel data as a mutable u8 slice.

Returns the Image pixel data as a Vec<u8>.

This consumes the Image, so we do not need to copy its contents.

Returns the Image pixel data as an iterator of Colors.

Returns the Image pixel data as a Vec<Color>.

Panics

Panics if the image has an invalid sequence of bytes given it’s PixelFormat.

Returns the color value at the given (x, y) position.

Panics

Panics if the image has an invalid sequence of bytes given it’s PixelFormat, or the (x, y) index is out of range.

Sets the color value at the given (x, y) position.

Update the Image with a u8 slice representing RGB/A values.

Returns the Image pixel format.

Save the Image to a png file.

Errors

Returns an error for any of the following: - An io::Error occurs attempting to create the png file. - A png::EncodingError occurs attempting to write image bytes.

Example
fn on_key_pressed(&mut self, s: &mut PixState, event: KeyEvent) -> PixResult<bool> {
    if let Key::S = event.key {
        self.image.save("test_image.png")?;
    }
    Ok(false)
}

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.