Load ChartImage images on demand.

master
Pacman Ghost 5 years ago
parent 939f0e83e1
commit 7a534c1939
  1. 20
      src/ChartImage.cs
  2. 2
      src/MainForm.ui.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 ; } }
}

@ -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 ) ;

Loading…
Cancel
Save