Problem with Bitmap loading

D

Davide

I need to load very big images (4096x4096 and even more), but when I try to
load it with:

Bitmap bm = new Bitmap(FileName);

it gives me the OutOfMemory Exception

This images is 4096x4096 with 1 bit depth stored as bmp images (in future
I'm going to load jpeg,gif and tiff)

and with Embedded visual Basic 3 I can load trem.

Does anyone know some limit/problem with .net cf ?

I think that at load time, the image is converted in RGB pixelformat so...
the image will be more times larger in bytes....but...I'm not sure.

Thanks Davide
 
A

Alex Feinman [MVP]

All bitmaps are loaded as matching bit depth of the actual screen. you end
up with 32 MB one, which causes out of memory condition.
At present CF cannot handle the bitmaps that are this large
 
D

Davide

Thanks alex for the help :)
So, if I load the image directly by means of the Win32 API using P/Invoke technology can I resolve
the problem or I will obtain the same results?
Thanks Davide
 
A

Alex Feinman [MVP]

Let's see. If you can load this from eVB code, you definitiely can load it
via P/Invoke. You will to do the painting via P/Invoke as well though
 
P

Peter Foot [MVP]

Alex Yakhnin's BitmapEx class in the Smart Device Framework
(www.opennetcf.org/sdf/) may contain all the functionality you need, you can
create a BitmapEx from a filename and then use GraphicsEx to draw this - its
all done using native GDI P/Invokes, so could probably save you some time -
I assume this will respect the bit-depth of the source image, but admit I
haven't tested the theory.

Peter
 
D

Davide

Hallo Peter
I have already used the BitmapEx of opencf but... I have the same problem :-(
I also go into the source code..

public BitmapEx(string filename)
{
if (File.Exists(filename))
{
hBitmap = GDIPlus.SHLoadImageFile(filename);<--------------------
//hBitmap = GDIPlus.LoadImageDec(filename);

if (hBitmap == IntPtr.Zero)
throw new FileNotFoundException("Invalid image file.");

GDIPlus.BITMAP bm = new GDIPlus.BITMAP();

GDIPlus.GetObject(hBitmap, Marshal.SizeOf(bm), ref bm);
width = bm.bmWidth; // Get width of bitmap
height = bm.bmHeight; // Get height of bitmap
widthBytes = bm.bmWidthBytes;
bitsPixel = bm.bmBitsPixel;

}
else
throw new FileNotFoundException("Image file doesn't exist.");
}
this is the opencf source code library, and i think that SHLLoadImageFile (taken directly from
gdi I saw) has the same problem...
The max bitmap loaded is 2560x2560 and when I try to load a 3072x3072 image it goes to outofmemory
"Invalid image file" exception (and I assure you that the files is correct...):-(
I'm thinking to use the standart CreateDIBSection and fill all the structure manually using the well
know libtiff,jpeglib (compiled from vce if i can compile it) and using the standard libray functions
for bmp files.
If you have another suggest please,send me.

Bye,

Davide
 

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