Question Load large image into a Bitmap object

jason2li

Member
Joined
Nov 18, 2005
Messages
22
Location
St. Louis, MO
Programming Experience
5-10
I have a large image (PNG: 22,550 x 16,7000) that I need to somehow split into several 256x256 JPG tiles.

But when I try to load it into a Bitmap (or Image) object, I keep getting an "Out of Memory Exception" error.

So, I was wondering if there is a better way to split an image up? Or is there a way to increase the allowed memory for my application.

I tried 2 different versions:

Code:
[COLOR="Red"]Dim bmp As Bitmap = Bitmap.FromFile(path)[/COLOR]
And:

Code:
Dim f As New FileStream(path, FileMode.Open)
Dim fi As New FileInfo(path)
Dim b(fi.Length) As Byte
f.Read(b, 0, b.Length)
f.Close()
Dim stream As New MemoryStream(b)
[COLOR="Red"]Dim bmp As New Bitmap(stream)[/COLOR]
But either way I do it, it throws an "Out of Memory" exception.

Thanks in advance!
 

gullible77

New member
Joined
May 27, 2008
Messages
4
Programming Experience
3-5
I guess you could try converting it to a bitmap (easy to work with) and then creating an application to make bitmaps out of the raw data and convert all of the 256x256 bmp files to jpeg..
Do you know any other programming languages? Maybe something like C# will handle it.. probably unlikely.
 

Stonkie

Well-known member
Joined
Sep 12, 2007
Messages
279
Programming Experience
1-3
I would think that it is possible to read only part of a bmp file and interpret the bits as an horizontal portion of the image. But most likely, if you cannot hold the file in memory, you probably cannot convert it to bmp whatever the program you use...

In bitmap format, I think an image 22,550 x 16,700 pixels with 32 bits per pixel should take about 1.5 GB plus some insignificant overhead. Maybe the cheapest way is to buy some RAM? Then I think there is an option in the machine.config file that allows you to tell what percentage of the RAM the .NET framework is allowed to use. I do not know if this applies to ASP.NET only or the whole framework...

Here is a link, use at your own risks... http://channel9.msdn.com/wiki/default.aspx/GuidanceLibrary.ConfigureMemoryLimit

This is all just a list of thinkgs to try, but I admit I never had to try any of those...
 
Top Bottom