C# Image

G

Guest

I am developing an application that possibly opens very large images - bmp,
jpeg, tiff. I have 2 questions:

Language: C#, VS .NET 2003.

1. When the program opens a BMP image, the amount of memory used seems to be
larger for BMP files than JPEGs with the same pixel dimensions. For example,
5200 x 5000 pixels image -- increase in Mem Usage is about 80MB for JPEG, but
200MB for BMP (with Task Manager). The Mem Usage is noted before and after
the following command:
Image image = new Bitmap(filename);
Is there something going on here? While this does not really matter
normally, it leads to the second question below.

2. I am getting "Out of Memory" exceptions if I open a large enough image or
a few large images. (I notice that this happens when the Mem Usage exceeds
1GB for the process when checked with Task Manager - the PC used has 2.5GB
RAM). Is there any setting that is needed to enable the application to deal
with such large images (assuming that the RAM can be increased if required)?
 
R

Rickard

Do you really need the whole of that image? If the image is that large,
maybe it suffices to work with parts of the image.

/ Rickard
 
K

Kevin Spencer

1. When the program opens a BMP image, the amount of memory used seems to
be
larger for BMP files than JPEGs with the same pixel dimensions. For
example,
5200 x 5000 pixels image -- increase in Mem Usage is about 80MB for JPEG,
but
200MB for BMP (with Task Manager). The Mem Usage is noted before and after
the following command:
Image image = new Bitmap(filename);
Is there something going on here? While this does not really matter
normally, it leads to the second question below.

Yes, there's something going on. JPG format supports compression, while BMP
does not.
2. I am getting "Out of Memory" exceptions if I open a large enough image
or
a few large images. (I notice that this happens when the Mem Usage exceeds
1GB for the process when checked with Task Manager - the PC used has 2.5GB
RAM). Is there any setting that is needed to enable the application to
deal
with such large images (assuming that the RAM can be increased if
required)?

It may be necessary to process the image in chunks. That is, open the image
file, using a stream, and read part of the image file into memory prior to
working with it.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

It takes a tough man to make a tender chicken salad.
 
G

Guest

Thanks for the response.

1. Sorry the question was not too clear. It's true JPEG is compressed while
on disk. The JPEG file size was only about 1.5MB. But once it is opened as a
Bitmap, the expected memory usage should be width x height x 4 bytes - the
size noted for the bitmap loaded from JPEG was quite close [slightly smaller]
to the expected but the BMP is almost double (and that is the puzzle). The
current workaround used is...

Image image1 = new Bitmap("sample.bmp"); //use ~200MB
Image image2 = new Bitmap(image1); //use ~100MB
image1.Dispose();
// use image2 from this point onwards.

Having to use this method has its drawback - more memory is used while both
image1 and image2 are opened so this decreases the largest image size
possible. This is the reason why I am trying to understand what is happening
with line 1.

2. The user is allowed to draw on or edit the image just like a picture
editor. Is there any way to avoid dealing with chunks of the image even if
that is possible in this application? Like -- probably a way to maximize the
memory usage. A 32 bit machine should allow up to 4GB memory usage but the
current ceiling seems to be around 1GB.

LTAng
 
R

Rickard

Maybe this is similar to your problem?
http://groups.google.se/group/micro...792d9534?lnk=st&rnum=2&hl=sv#989a5f29792d9534



LT.Ang said:
Thanks for the response.

1. Sorry the question was not too clear. It's true JPEG is compressed while
on disk. The JPEG file size was only about 1.5MB. But once it is opened as a
Bitmap, the expected memory usage should be width x height x 4 bytes - the
size noted for the bitmap loaded from JPEG was quite close [slightly smaller]
to the expected but the BMP is almost double (and that is the puzzle). The
current workaround used is...

Image image1 = new Bitmap("sample.bmp"); //use ~200MB
Image image2 = new Bitmap(image1); //use ~100MB
image1.Dispose();
// use image2 from this point onwards.

Having to use this method has its drawback - more memory is used while both
image1 and image2 are opened so this decreases the largest image size
possible. This is the reason why I am trying to understand what is happening
with line 1.

2. The user is allowed to draw on or edit the image just like a picture
editor. Is there any way to avoid dealing with chunks of the image even if
that is possible in this application? Like -- probably a way to maximize the
memory usage. A 32 bit machine should allow up to 4GB memory usage but the
current ceiling seems to be around 1GB.

LTAng


Kevin Spencer said:
Yes, there's something going on. JPG format supports compression, while BMP
does not.

It may be necessary to process the image in chunks. That is, open the image
file, using a stream, and read part of the image file into memory prior to
working with it.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

It takes a tough man to make a tender chicken salad.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top