mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 05:53:41 +02:00
UI image selection (#97)
This commit is contained in:
@@ -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)?;
|
||||
|
||||
Reference in New Issue
Block a user