Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

bitMapEx error

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-13-2009, 08:02 PM
Saj Saj is offline
Senior Member
 
Join Date: Dec 2007
Location: Manchester, UK
Posts: 105
Default bitMapEx error

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?

Saj.
Reply With Quote
  #2 (permalink)  
Old 09-14-2009, 06:11 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,734
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

You should change this line:
Code:
<i>bitmapMapEx.Value = (AppPath & "\" & s)
</i>

to:
Code:
<i>bitmapMapEx.Value = AppPath & "\" & s
</i>
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.
Reply With Quote
  #3 (permalink)  
Old 09-14-2009, 08:51 PM
Saj Saj is offline
Senior Member
 
Join Date: Dec 2007
Location: Manchester, UK
Posts: 105
Default

Thanks Erel,

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?

Last edited by Saj : 09-14-2009 at 09:23 PM.
Reply With Quote
  #4 (permalink)  
Old 09-15-2009, 09:28 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
bitmapMapEx.Value = AppPath & "\" & s
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.

Code:
BitmapEx.Dispose
BitmapEx.New1(AppPath & 
"\" & s)
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
  #5 (permalink)  
Old 09-15-2009, 12:07 PM
Saj Saj is offline
Senior Member
 
Join Date: Dec 2007
Location: Manchester, UK
Posts: 105
Default

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.
Reply With Quote
  #6 (permalink)  
Old 09-15-2009, 12:37 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

That will be because it hasn't been Newed before. You can't Dispose something that doesn't exist.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
  #7 (permalink)  
Old 09-15-2009, 02:53 PM
Saj Saj is offline
Senior Member
 
Join Date: Dec 2007
Location: Manchester, UK
Posts: 105
Default

Quote:
That will be because it hasn't been Newed before.
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
Reply With Quote
  #8 (permalink)  
Old 09-15-2009, 03:41 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Sorry, I didn't test it before posting like I usually do. It needs an AddObject after the Dispose.

AddObject("bitMapEx", "BitmapEx")
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
  #9 (permalink)  
Old 09-15-2009, 04:10 PM
Saj Saj is offline
Senior Member
 
Join Date: Dec 2007
Location: Manchester, UK
Posts: 105
Default

Ah, i see, it goes more than clearing the instance of the object, kills it too.

Just tried it on an old device with not much memory and its fixed the memory error.

Many Thanks
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On


All times are GMT. The time now is 10:24 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0