UI image selection (#97)

This commit is contained in:
Philip Kristoffersen
2022-04-23 20:33:16 +02:00
committed by GitHub
parent 91782b74eb
commit e77f2b5f31
49 changed files with 1368 additions and 801 deletions
+10
View File
@@ -11,6 +11,8 @@ pub mod ui_colors {
}
pub mod ui_images {
use std::path::Path;
use eframe::epi::IconData;
use egui::{ColorImage, ImageData};
@@ -36,6 +38,14 @@ pub mod ui_images {
rgba: pixels.as_slice().to_vec(),
}
}
pub fn load_image_from_path(path: &Path) -> Option<ColorImage> {
if path.exists() {
if let Ok(data) = std::fs::read(path) {
return load_image_from_memory(&data).ok();
}
}
None
}
fn load_image_from_memory(image_data: &[u8]) -> Result<ColorImage, image::ImageError> {
let image = image::load_from_memory(image_data)?;