Struct sixtyfps::Image[]

#[repr(transparent)]
pub struct Image(_);
Expand description

An image type that can be displayed by the Image element. You can construct Image objects from a path to an image file on disk, using Self::load_from_path.

Another typical use-case is to render the image content with Rust code. For this it’s most efficient to create a new SharedPixelBuffer with the known dimensions and pass the the mutable slice to your rendering function. Afterwards you can create an Image.

The following example creates a 320x200 RGB pixel buffer and calls an external low_level_render() function to draw a shape into it. Finally the result is stored in an Image with Self::from_rgb8():


fn low_level_render(width: usize, height: usize, buffer: &mut [u8]) {
    // render beautiful circle or other shapes here
}

let mut pixel_buffer = SharedPixelBuffer::<Rgb8Pixel>::new(320, 200);

low_level_render(pixel_buffer.width(), pixel_buffer.height(),
                 pixel_buffer.make_mut_bytes());

let image = Image::from_rgb8(pixel_buffer);

Another use-case is to import existing image data into SixtyFPS, by creating a new Image through cloning of another image type.

The following example uses the popular image crate to load a .png file from disk, apply brightening filter on it and then import it into an Image:

let mut cat_image = image::open("cat.png").expect("Error loading cat image").into_rgba8();

image::imageops::colorops::brighten_in_place(&mut cat_image, 20);

let buffer = SharedPixelBuffer::<Rgba8Pixel>::clone_from_slice(
    cat_image.as_raw(),
    cat_image.width() as _,
    cat_image.height() as _,
);
let image = Image::from_rgba8(buffer);

Implementations

Load an Image from a path to a file containing an image

Creates a new Image from the specified shared pixel buffer, where each pixel has three color channels (red, green and blue) encoded as u8.

Creates a new Image from the specified shared pixel buffer, where each pixel has four color channels (red, green, blue and alpha) encoded as u8.

Creates a new Image from the specified shared pixel buffer, where each pixel has four color channels (red, green, blue and alpha) encoded as u8 and, in contrast to Self::from_rgba8, the alpha channel is also assumed to be multiplied to the red, green and blue channels.

Only construct an Image with this function if you know that your pixels are encoded this way.

Returns the size of the Image in pixels.

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

Performs the conversion.

Performs the conversion.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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.