bitmap file too big

  • Thread starter Thread starter carmen
  • Start date Start date
C

carmen

I'm trying to work with a big bmp file (240.000 bytes) and get an
OutOfMemory exception in this sentence:

Bitmap myBmp = new Bitmap(myFileName);

Is there anything that I could do?

Thank you!

Carmen
 
Hi,

Are you working in a PocketPC device?
That is around 240 MB almost the double of what the regular device has.


cheers,
 
240 KB of a monochrome bitmap is 16 times that when loaded (16bpp vs 1
bpp) - 3MB may get you out of memory if the device is short on it
 
I'm trying to work with a big bmp file (240.000 bytes) and get an
OutOfMemory exception in this sentence:

Bitmap myBmp = new Bitmap(myFileName);
The problem is that the bitmaps are loaded as matching bit depth of the actual screen.
So 24 bit in our case even if your bitmap has 1 bitdepth... so if you load a very big bitmap...you
will go in out of memory.
I resolved the problem by means the GDI function using Platform/Invoke technology together with
OpenNETCF.


Bye...
Davide
 
Davide,
what functions did you PInvoke and what OpenNETCF classes did you use?
Thank you for your help!
Carmen
 
Hi Carmen,
sorry for my later but today I haven't readed this newsgroup :-P

Ok let's go:
I have modified The OpenNetCF.Drawing.BitmMapEx class in a way that
I can create a BitmapEx object by a HBITMAP handler created with
CreateDIBSection function using the OpenNetCF.Drawing.GDIPlus class ( I make them
public instead of internal....)
After I created the
GDIPlus.BITMAPINFO structure declared in this way:


public struct RGBQUAD
{
public byte rgbBlue;
public byte rgbGreen;
public byte rgbRed;
public byte rgbReserved;

}

[CLSCompliantAttribute(false)]
public struct BITMAPINFO
{
public BITMAPINFOHEADER bmiHeader;
public RGBQUAD bmiColors0;
public RGBQUAD bmiColors1;
}



After that I created the bitmap with this code:

IntPtr s;
unsafe
{
GDIPlus.BITMAPINFO info;

info.bmiHeader.biBitCount = 1;
info.bmiHeader.biPlanes = 1;
info.bmiHeader.biHeight = 10000;
info.bmiHeader.biWidth = 10000;
info.bmiHeader.biCompression = 0; //BI_RGB
info.bmiHeader.biClrUsed = 2;
//this should be 40
info.bmiHeader.biSize = (uint)sizeof(GDIPlus.BITMAPINFOHEADER);

IntPtr pBits = IntPtr.Zero;
IntPtr hFile = IntPtr.Zero;
hBitmap = GDIPlus.CreateDIBSection(IntPtr.Zero,pInfo,0,ref pBits,hFile,0);

for (int y = 0; y < 30; y++ )
{
for (int x = 0; x < 30; x++ )
{
byte* pointer = (byte *)pBits.ToPointer();
pointer[ x + y * 10 ] = 0;
}
}
}
m_BitMap = new BitmapEx(hBitmap);

as you can see, now I can crate and draw (With OpenNETCF.Drawing.GraphicEx.DrawImage) 10000 x 10000
bitmap with 1 bitdepth.
:-P

note: the double for cicle is not correct, I know, but this is only example to see
if this approach was correct.

note2: when you make GDIPlus pubblic You will see many compile error (40 or 50 more or less)
that says the element "bla bla" is not CLSCompliant...so before that you write:
[CLSCompliantAttribute(false)]

and the problem is resolved



bye Davide
 
Back
Top