spottedcat 0.6.0

Rusty SpottedCat simple game engine
Documentation
1
2
3
4
5
6
7
8
9
10
use crate::Image;
use image::GenericImageView;

/// Loads an image from a byte slice (PNG, JPEG, etc.).
pub fn load_image_from_bytes(ctx: &mut crate::Context, data: &[u8]) -> anyhow::Result<Image> {
    let img = image::load_from_memory(data)?;
    let (w, h) = img.dimensions();
    let rgba = img.to_rgba8();
    Image::new_from_rgba8(ctx, w.into(), h.into(), &rgba)
}