Loading big image. Please help.

  • Thread starter Thread starter woth
  • Start date Start date
W

woth

Hello guys,

I hope you can help me. I have the following line in my code:

this.Butterfly = new Bitmap("c:\\butterfly.jpg");

which is pretty simple. The problem is that the size of butterfly.jpg
is 70 megs :) Of course, the program can't load it and i have the out
of memory exception.

My question is: how can I open that file? Please, give me some hints on
how to approach in this situation.

Thank you.
 
Hi...

There are several possibilities.

1. Look into using a Memory Mapped File. You may need to use Interop (not
sure if the framework implements wrappers).
2. Chunk your reading by using a Binary Stream. Open the Binary Stream and
read N bytes per chunk. As long as you have memory, stich the chunks
together until you complete reading in the entire file.
3. Save the image at a lower resoution/depth. Many times, JPEG files do
not degrade as quickly as you might anticipate.

John Puopolo
 
Firstly, what on earth do you need a 70MB jpeg of a butterfly for? ;)

Image Class size limit in GDI+ is 16Mb (2048x2048, 24bpp).

Let's say you want to display the image in a PictureBox on a WinForm. You
would actually need to create an algorithm to read chunks of the image into
a binary memory stream array. Then you would have to tile the pieces into a
series of Boxes keeping track of the alignment and order. You may end up
running out of system memory before its done!

In DirectX your texture size is limited by hardware. You can check your
D3DCaps to see what the max allowable is but I am sure you would still need
to chunkify and tile an image that large.

Remember, try microsoft.public.dotnet.framework.drawing for expertise on
gdi+...

ok,
aq
 
It is a big trouble. I think the bitmap class loads your jpeg into a bitmap
format. Suppose your jpeg has a 1:8 compression ratio. The bitmap is 560MB!
Do you think you can store such a class in your memory?
Try declaring a picturebox and write:
pictureBox1.Image = Image.FromFile("c:\\butterfly.jpg");
I doubt if this will work. If not, you need to learn the jpeg file format
and open the file with StreamReader and read some data each time.
 
Back
Top