In order to prevent OutOfMemoryException errors I want to load large images as needed, rather than loading all into an ImageList array at the start. So i'm initializing a BitMapEx object as follows in App_Start: bitmapMapEx.New1 (AppPath & "\blank.jpg")
Then I tried executing the following: Sub LoadImage
s = imageFileArr(imageIndex).imagename 'string
bitmapMapEx.Value = (AppPath & "\" & s)
End Sub
The result is that I get an error message saying the Input string was not in the correct format.
Is my thinking correct - will it prevent the OutOfMemeoryException error? and what is causing the 'Input String' error?
Your approach seems to be correct assuming that not all images will be eventually required. You should take care not to reload the same image multiple times as it will increase the memory required.
Is it possible to discard the current image to free up memory before loading a new image - that way the same image can be loaded/unloaded many times?
The next line of code I have is as follows: bitmapMapEx.Value = AppPath & "\" & s
MapWidth=bitmapMapEx.Width
MapHeight=bitmapMapEx.Height
which gives the following error: Object reference not set to an instance of an object. Can't figure out this error since bitmapMapEx.New1 has been executed in App_Start?
This is not valid. You can't assign a string to the Value property, it only accepts a reference to an existing image. To create a BitmapEx from a path you need to use New1 again. It may not be necessary but to be safe I would Dispose of the old BitmapEx first.
Adding in BitmapEx.Dispose before BitmapEx.New1(AppPath & "\" & s) causes the following error on the New1 line:
Object reference not set to an instance of an object.
I was already initialising bitMapEx in App_Start. The code wasn't failing on the Dispose method, but on the New1 after it. The code I have is as follows:
Sub App_Start
bitMapEx.New1(AppPath & "\blank.jpg")
End Sub
Sub LoadImage
s = mapIniFileArr(mapIndex).imagename
bitMapEx.Dispose
bitMapEx.New1(AppPath & "\" & s)
End Sub