@@ -9,7 +9,7 @@ use eframe::egui::{
9
9
} ;
10
10
use eframe:: glow:: HasContext ;
11
11
use eframe:: { egui, glow, Storage } ;
12
- use image:: RgbaImage ;
12
+ use image:: { ImageResult , RgbaImage } ;
13
13
use preferences:: Preferences ;
14
14
use serde:: { Deserialize , Serialize } ;
15
15
use std:: ops:: RangeInclusive ;
@@ -602,8 +602,25 @@ impl eframe::App for MyApp {
602
602
self . gui_conf . y = ctx. used_size ( ) . y ;
603
603
604
604
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
+ }
607
624
}
608
625
609
626
std:: thread:: sleep ( Duration :: from_millis ( ( 1000.0 / MAX_FPS ) as u64 ) ) ;
@@ -667,7 +684,7 @@ impl eframe::App for MyApp {
667
684
}
668
685
}
669
686
670
- fn save_image ( img : & ColorImage , file_path : & PathBuf ) {
687
+ fn save_image ( img : & ColorImage , file_path : & PathBuf ) -> ImageResult < ( ) > {
671
688
let height = img. height ( ) ;
672
689
let width = img. width ( ) ;
673
690
let mut raw: Vec < u8 > = vec ! [ ] ;
@@ -679,10 +696,5 @@ fn save_image(img: &ColorImage, file_path: &PathBuf) {
679
696
}
680
697
let img_to_save = RgbaImage :: from_raw ( width as u32 , height as u32 , raw)
681
698
. 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)
688
700
}
0 commit comments