diff --git a/src/ChartImage.cs b/src/ChartImage.cs index 46d7292..09c81cd 100644 --- a/src/ChartImage.cs +++ b/src/ChartImage.cs @@ -25,7 +25,7 @@ public class ChartImage // initialize the ChartImage mFullPath = fullPath ; mJsonConfig = new JsonConfig( config ) ; - mImage = Image.FromFile( fullPath ) ; + mImage = null ; // nb: we load this on demand // parse the shortcut ILog logger = LogManager.GetLogger( "shortcuts" ) ; @@ -155,8 +155,24 @@ public class ChartImage ) ; } + public Image image() + { + // return the image data + // NOTE: It would be nice to reuse the ImageListView cache, but it only seems to cache thumbnails. + if ( mImage == null ) { + try { + mImage = Image.FromFile( mFullPath ) ; + } catch( Exception ex ) { + // NOTE: This crashes on Linux, but we can live with that - ChartImage's are created by iterating + // over files in the data directory, so if we can't load the file, it'll be because the file was deleted + // after startup, or a permissions problem i.e. things we don't really need to worry about. + Program.showErrorMsg( $"Can't load image file:\n {mFullPath}\n\n{ex}" ) ; + } + } + return mImage ; + } + public JsonConfig jsonConfig { get { return mJsonConfig ; } } - public Image image { get { return mImage ; } } public ImageListViewItem imageListViewItem { get { return mImageListViewItem ; } } } diff --git a/src/MainForm.ui.cs b/src/MainForm.ui.cs index 2f07868..c946763 100644 --- a/src/MainForm.ui.cs +++ b/src/MainForm.ui.cs @@ -439,7 +439,7 @@ public partial class MainForm : Form double maxZoom = Program.dataConfig.getDoubleVal( new string[]{"_MaxZoom"}, 2*userZoom ) ; if ( mSearchResults.SelectedItems.Count > 0 ) { ChartImage chartImage = (ChartImage) mSearchResults.SelectedItems[0].Tag ; - mChartImagePictureBox.Image = chartImage.image ; + mChartImagePictureBox.Image = chartImage.image() ; userZoom = chartImage.jsonConfig.getDoubleVal( new string[]{"defaultZoom"}, userZoom ) ; minZoom = chartImage.jsonConfig.getDoubleVal( new string[]{"minZoom"}, minZoom ) ; maxZoom = chartImage.jsonConfig.getDoubleVal( new string[]{"maxZoom"}, maxZoom ) ;