@@ -9,7 +9,7 @@ use eframe::egui::{
99} ;
1010use eframe:: glow:: HasContext ;
1111use eframe:: { egui, glow, Storage } ;
12- use image:: RgbaImage ;
12+ use image:: { ImageResult , RgbaImage } ;
1313use preferences:: Preferences ;
1414use serde:: { Deserialize , Serialize } ;
1515use std:: ops:: RangeInclusive ;
@@ -602,8 +602,25 @@ impl eframe::App for MyApp {
602602 self . gui_conf . y = ctx. used_size ( ) . y ;
603603
604604 if let Some ( plot_to_save) = self . plot_to_save . take ( ) {
605- println ! ( "saving plot..." ) ;
606- save_image ( & plot_to_save, & self . picked_path_plot ) ;
605+ // maybe we should put this in a different thread, so that the GUI
606+ // doesn't lag during saving
607+ match save_image ( & plot_to_save, & self . picked_path_plot ) {
608+ Ok ( _) => {
609+ print_to_console (
610+ & self . print_lock ,
611+ Print :: Ok ( format ! ( "saved data file to {:?} " , self . picked_path_plot) ) ,
612+ ) ;
613+ }
614+ Err ( e) => {
615+ print_to_console (
616+ & self . print_lock ,
617+ Print :: Error ( format ! (
618+ "failed to save file to {:?}: {:?}" ,
619+ self . picked_path_plot, e
620+ ) ) ,
621+ ) ;
622+ }
623+ }
607624 }
608625
609626 std:: thread:: sleep ( Duration :: from_millis ( ( 1000.0 / MAX_FPS ) as u64 ) ) ;
@@ -667,7 +684,7 @@ impl eframe::App for MyApp {
667684 }
668685}
669686
670- fn save_image ( img : & ColorImage , file_path : & PathBuf ) {
687+ fn save_image ( img : & ColorImage , file_path : & PathBuf ) -> ImageResult < ( ) > {
671688 let height = img. height ( ) ;
672689 let width = img. width ( ) ;
673690 let mut raw: Vec < u8 > = vec ! [ ] ;
@@ -679,10 +696,5 @@ fn save_image(img: &ColorImage, file_path: &PathBuf) {
679696 }
680697 let img_to_save = RgbaImage :: from_raw ( width as u32 , height as u32 , raw)
681698 . expect ( "container should have the right size for the image dimensions" ) ;
682- match img_to_save. save ( file_path) {
683- Ok ( _) => { }
684- Err ( err) => {
685- println ! ( "error in saving image: {err:?}" ) ;
686- }
687- }
699+ img_to_save. save ( file_path)
688700}
0 commit comments