PC Review


Reply
Thread Tools Rate Thread

bitmap memory limit?

 
 
Tony Hsieh
Guest
Posts: n/a
 
      20th Nov 2003
Hi,

When I try to load anything over 134 bitmaps of size 240x320 into
memory, I get an ArgumentException in the Bitmap constructor.
Anything up to 134 works great and once I try to load image 135 it
fails. The code that works fine is:

images = new Bitmap[photos.Count];
for (int i=0;i<134;i++)
{
images[i] = new Bitmap(photos[i].fileName);
}

Once i change the 134 to anything greater than 134, I get the
exception. I find this very strange that is works fine up to a
certain number. When I look at Memory, I still have 20MB free even
after loading 134 images. Is there some sort of lock that is
preventing me from loading more images? Any help be greatly
appreciated. Thanks so much.

-Tony
 
Reply With Quote
 
 
 
 
Eric Bouchard
Guest
Posts: n/a
 
      20th Nov 2003
Hi Tony,

Could you possibly be running out of memory?

Eric


>-----Original Message-----
>Hi,
>
>When I try to load anything over 134 bitmaps of size

240x320 into
>memory, I get an ArgumentException in the Bitmap

constructor.
>Anything up to 134 works great and once I try to load

image 135 it
>fails. The code that works fine is:
>
>images = new Bitmap[photos.Count];
>for (int i=0;i<134;i++)
>{
> images[i] = new Bitmap(photos[i].fileName);
>}
>
>Once i change the 134 to anything greater than 134, I

get the
>exception. I find this very strange that is works fine

up to a
>certain number. When I look at Memory, I still have

20MB free even
>after loading 134 images. Is there some sort of lock

that is
>preventing me from loading more images? Any help be

greatly
>appreciated. Thanks so much.
>
>-Tony
>.
>

 
Reply With Quote
 
Alex Feinman [MVP]
Guest
Posts: n/a
 
      20th Nov 2003
You might be running out of GDI memory which is a small subset of the
overall system memory. Consider loading these bitmaps on demand

"Tony Hsieh" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> When I try to load anything over 134 bitmaps of size 240x320 into
> memory, I get an ArgumentException in the Bitmap constructor.
> Anything up to 134 works great and once I try to load image 135 it
> fails. The code that works fine is:
>
> images = new Bitmap[photos.Count];
> for (int i=0;i<134;i++)
> {
> images[i] = new Bitmap(photos[i].fileName);
> }
>
> Once i change the 134 to anything greater than 134, I get the
> exception. I find this very strange that is works fine up to a
> certain number. When I look at Memory, I still have 20MB free even
> after loading 134 images. Is there some sort of lock that is
> preventing me from loading more images? Any help be greatly
> appreciated. Thanks so much.
>
> -Tony



 
Reply With Quote
 
Bill Draper
Guest
Posts: n/a
 
      21st Nov 2003
Tony,

Just a quick math exercise shows (assuming 2-bytes per pixel color, or 16
bit color)

240 x 2 x 320 = 153,600 bytes per image. 153,600 x 134 images = 20,582,400
bytes, or approx 20 MB!

When you look at memory, I assume you mean system RAM. Windows CE gives each
process a 32 MB 'process space' to run in, and I've always assumed that the
Compact Framework CLR is bound by this 32 MB box (empirical tests show this
to be the case.) That leaves about 12 MB left in your process space. I
assume the CLR itself will occupy part of this space, along with your
managed code and cached JIT'ed code (which I THINK goes into the managed
heap.) There may also be other things that are taking up space from your
process.

Much of this is conjecture on my part, and more info would be needed to fill
in all the pieces (such as what you're using to determine 20 MB free, and
just a more thorough understanding of how CE memory mgt and the CLR work
under the hood) but it's not hard to imagine that you're running out of
memory in your process space using this technique.

Consider whether you can load them on demand and purge when no longer
needed.

Bill


"Tony Hsieh" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> When I try to load anything over 134 bitmaps of size 240x320 into
> memory, I get an ArgumentException in the Bitmap constructor.
> Anything up to 134 works great and once I try to load image 135 it
> fails. The code that works fine is:
>
> images = new Bitmap[photos.Count];
> for (int i=0;i<134;i++)
> {
> images[i] = new Bitmap(photos[i].fileName);
> }
>
> Once i change the 134 to anything greater than 134, I get the
> exception. I find this very strange that is works fine up to a
> certain number. When I look at Memory, I still have 20MB free even
> after loading 134 images. Is there some sort of lock that is
> preventing me from loading more images? Any help be greatly
> appreciated. Thanks so much.
>
> -Tony



 
Reply With Quote
 
Bill
Guest
Posts: n/a
 
      23rd Nov 2003
You might try the following and see if it works or at least increases
the number of bitmaps you can load...

Change your code as follows:

1) Embed the graphic files in you project as a resource (e.g. click on
the file name and change the "build action" property from "content" to
"embedded resource" (I'm assuming these files are inlcuded in the
project as content files)

2) Change you code to mimic the code that follows:

images = new Bitmap[200];
for (int i=0;i<134;i++)
{
images[i] = setbm(fname);
}


private Bitmap setbm()
{
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(Form1)); //assumes pictures
are loaded at design time into picture boxes on form1)

return (System.Drawing.Bitmap)((System.Drawing.Image)(resources.GetObject(fname)));
}


Bill


(E-Mail Removed) (Tony Hsieh) wrote in message news:<(E-Mail Removed)>...
> Hi,
>
> When I try to load anything over 134 bitmaps of size 240x320 into
> memory, I get an ArgumentException in the Bitmap constructor.
> Anything up to 134 works great and once I try to load image 135 it
> fails. The code that works fine is:
>
> images = new Bitmap[photos.Count];
> for (int i=0;i<134;i++)
> {
> images[i] = new Bitmap(photos[i].fileName);
> }
>
> Once i change the 134 to anything greater than 134, I get the
> exception. I find this very strange that is works fine up to a
> certain number. When I look at Memory, I still have 20MB free even
> after loading 134 images. Is there some sort of lock that is
> preventing me from loading more images? Any help be greatly
> appreciated. Thanks so much.
>
> -Tony

 
Reply With Quote
 
Joe Audette
Guest
Posts: n/a
 
      1st Dec 2003
Tony,

I don't think its a memory issue. I was getting similar
ArgumentException errors and it turned out that the
bitmaps I was trying to load were 32 bit resolution. To
fix it I had to save the bitmaps as 24 bit resolution.

I would bet that the 135th image is more than 24 bit
resolution.

Best Regards,

Joe Audette

>-----Original Message-----
>Hi,
>
>When I try to load anything over 134 bitmaps of size

240x320 into
>memory, I get an ArgumentException in the Bitmap

constructor.
>Anything up to 134 works great and once I try to load

image 135 it
>fails. The code that works fine is:
>
>images = new Bitmap[photos.Count];
>for (int i=0;i<134;i++)
>{
> images[i] = new Bitmap(photos[i].fileName);
>}
>
>Once i change the 134 to anything greater than 134, I

get the
>exception. I find this very strange that is works fine

up to a
>certain number. When I look at Memory, I still have

20MB free even
>after loading 134 images. Is there some sort of lock

that is
>preventing me from loading more images? Any help be

greatly
>appreciated. Thanks so much.
>
>-Tony
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel Memory Error Insufficient Memory to Create the Bitmap Cassandra Lindquist Microsoft Excel Crashes 0 31st Dec 2007 07:26 PM
My available memory is down to very little, yet my PF Usage is 8 gigabytes (about how much memory is on the box), sql server keeps having memory issues yet the sqlservr.exe is using hardly any memory.. how to fix this? is there some way to limit how Daniel Microsoft Windows 2000 Security 1 30th Aug 2007 07:38 AM
My available memory is down to very little, yet my PF Usage is 8 gigabytes (about how much memory is on the box), sql server keeps having memory issues yet the sqlservr.exe is using hardly any memory.. how to fix this? is there some way to limit how Daniel Microsoft Windows 2000 1 30th Aug 2007 01:22 AM
My available memory is down to very little, yet my PF Usage is 8 gigabytes (about how much memory is on the box), sql server keeps having memory issues yet the sqlservr.exe is using hardly any memory.. how to fix this? is there some way to limit how Daniel Microsoft Windows 2000 Networking 0 28th Aug 2007 12:38 AM
My available memory is down to very little, yet my PF Usage is 8 gigabytes (about how much memory is on the box), sql server keeps having memory issues yet the sqlservr.exe is using hardly any memory.. how to fix this? is there some way to limit how Daniel Microsoft Windows 2000 Advanced Server 0 28th Aug 2007 12:38 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:15 AM.