librashader/librashader-common/src/image.rs

22 lines
458 B
Rust
Raw Normal View History

2022-11-17 16:08:11 +11:00
use std::path::Path;
pub struct Image {
pub bytes: Vec<u8>,
pub height: u32,
pub width: u32,
}
impl Image {
pub fn load(path: impl AsRef<Path>) -> Result<Self, image::ImageError>{
2022-11-21 18:13:22 +11:00
let image = image::open(path.as_ref())?.flipv().to_rgba8();
2022-11-17 16:08:11 +11:00
let height = image.height();
let width = image.width();
Ok(Image {
bytes: image.to_vec(),
height,
width
})
}
}