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
impl Image
impl Image
pub fn load_from_path(path: &Path) -> Result<Image, LoadImageError>
pub fn load_from_path(path: &Path) -> Result<Image, LoadImageError>
Load an Image from a path to a file containing an image
pub fn from_rgb8(buffer: SharedPixelBuffer<RGB<u8>>) -> Image
pub fn from_rgb8(buffer: SharedPixelBuffer<RGB<u8>>) -> 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.
pub fn from_rgba8(buffer: SharedPixelBuffer<RGBA<u8, u8>>) -> Image
pub fn from_rgba8(buffer: SharedPixelBuffer<RGBA<u8, u8>>) -> Image
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.
pub fn from_rgba8_premultiplied(
buffer: SharedPixelBuffer<RGBA<u8, u8>>
) -> Image
pub fn from_rgba8_premultiplied(
buffer: SharedPixelBuffer<RGBA<u8, u8>>
) -> Image
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.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Image
impl UnwindSafe for Image
Blanket Implementations
Mutably borrows from an owned value. Read more