By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,081 Members | 2,118 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,081 IT Pros & Developers. It's quick & easy.

C# Image

P: n/a
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)?
Sep 6 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

LT.Ang wrote:
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)?
Sep 6 '06 #2

P: n/a
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.
"LT.Ang" <LT****@discussions.microsoft.comwrote in message
news:82**********************************@microsof t.com...
>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)?

Sep 6 '06 #3

P: n/a
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" wrote:
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.
"LT.Ang" <LT****@discussions.microsoft.comwrote in message
news:82**********************************@microsof t.com...
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)?


Sep 6 '06 #4

P: n/a
Maybe this is similar to your problem?
http://groups.google.se/group/micros...9a5f29792d9534

LT.Ang wrote:
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" wrote:
>>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.
"LT.Ang" <LT****@discussions.microsoft.comwrote in message
news:82**********************************@microso ft.com...
>>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)?

Sep 7 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.