.NET Framework Bookmark and Share   
 index > .NET Base Class Library > Problem with constructor Bitmap
 

Problem with constructor Bitmap

Hey,

If i'm trying to construct an new bitmap with follow parameters in the constructor (18200, 7400) (WxH) it works fine.

example:
Dim n As New Bitmap(18200, 7400)
n.Save("test2.bmp")
n.Dispose()


But if i'm trying to construct a new bitmap with these parameters given thru the properties of an other image (bitmap.width, bitmap.height) it doesn't work anymore.
example:
 Dim n As New Bitmap(18200, 7400)
n.Save("test2.bmp")
n.Dispose()
Dim b As New Bitmap("test2.bmp")
Dim t As New Bitmap(b.Width, b.Height)

You'll see that he gives now an error on the line were t is created. Errormessage: Invalid paramter used.

Does anybody now's how this is comming and how i can resolve it.

Thanks Tsjelle
Tsjelle
You have a 18200 X 7400 X 3= 404,040,000 byte bitmap in memory and then you try to allocate space for an additional18200 X 7200 X4 = 524,160,000 byte bitmap. The size limit for a gdi+ on a 32 bit system is about 500 MB, which you have exceeded by nearly 2X. If you hard code the size of the second bitmap, it must not be allocated until you use it. Leave it hard coded and try to use it. Even 64 bit systems aren't wild about 500 MB pictures. If you must work with large images, reduce them to the size of the display or save them in BMP format and work with them ondisk.
JohnWein
Use smaller bitmaps. What's the PixelFormat of n?
JohnWein
Thanks for the quick response.

I may not change the format of the bitmap.

I'm must change the HorizontalResolution and VerticalResolution of this bitmap. (Witch I can do thru the SetResolution method from the bitmap).

But like I said, must keep the original size.

Cheers Tsjelle

PS: Pixelformat will mostly be Format24bppRgb
Tsjelle
Do you have at least 4GB RAM and Vista64?
JohnWein
No,

I don't.
Tsjelle
That's what you'll need to handle code as you have written it.
JohnWein
I don't think so, because i run the code and it works. I just get an invalid parameter exception. And that's what i found not normal.

Because if i give the width and height as fixed values ex. 18200x7400 it works.
If i give the width and height as property values ex. bitmap.widthxbitmap.heigh it doesn't work.

That's my problem i don't understand that with the fixed values it works and with the dynamic values it doesn't work.
(The constructor of the bitmap that is).
Tsjelle
You got good advice from John. You are teetering on the very edge what is possible in a 32-bit operating system. That works only once, after that the address space is too fragmented to give you another chunk of 400+ megabytes of contiguous memory.

Isn't it odd that these posts about large bitmaps always use dimensions that just barely work? Nobody ever posts "Why can't I make 20,000 x 20,000 work".
Hans Passant.
nobugz
Right. The .NET/GDI+ libraries arenot really for working with such high resolution graphic files.

Goodgraphic editing applications do their own bitmap memory management to support such files instead of relying on the features of the OS.
BinaryCoder
Oke,

Thanks for the explaination guys.

I understand that this is sow.

But still, how come he accepts the fixed values and not the dynamic values.

I really find this weard, but never the less, I think that I'm going to have to find another solution for my problem.

Like u guys said, it's on the edge of the capacities of my machine.

Stil thanks for the answers.

Greetings Tsjelle
Tsjelle
You have a 18200 X 7400 X 3= 404,040,000 byte bitmap in memory and then you try to allocate space for an additional18200 X 7200 X4 = 524,160,000 byte bitmap. The size limit for a gdi+ on a 32 bit system is about 500 MB, which you have exceeded by nearly 2X. If you hard code the size of the second bitmap, it must not be allocated until you use it. Leave it hard coded and try to use it. Even 64 bit systems aren't wild about 500 MB pictures. If you must work with large images, reduce them to the size of the display or save them in BMP format and work with them ondisk.
JohnWein
I've forget to thank you guys.

Sow by this,

Thanks,

Tsjelle
Tsjelle

You can use google to search for other answers

Custom Search

More Threads

• Type 'xxx' is not defined... only under certain conditions...
• How to calcul a file's md5
• Format an Double Value
• Save my file with my extension
• encryption and decryption errors n exceptions
• office.interop.excel - Office11 and Office12 on Development PC
• RPC call
• Repeatable expression for a comma-separated list
• Only Success messages in a custom Event Log are properly displayed in the Event Viewer
• How to pass a image from c++ to Visual Basic