When I use the following code in a web page it works fine until my
Bitmap size gets to a certain size, e.g. 5214 x 3223. Then I get a red
cross, but no run time error occurs. What is the maxmum size of the
bitmap and how do I trap for the error?
Code is here. The actual details of what is draw is not relevant.
Dim objBitmap As Bitmap = New Bitmap(5214, 3223)
Dim objGraphics As Graphics = Graphics.FromImage(objBitmap)
' DRAWING CODE HERE
Response.ContentType = "image/gif"
objGraphics.DrawImage(objBitmap, 0, 0, objBitmap.Width,
objBitmap.Height)
objBitmap.Save(Response.OutputStream, ImageFormat.Gif)
objGraphics.Dispose()
objBitmap.Dispose()
Bob Powell [MVP] - 10 Apr 2008 00:01 GMT
The maximum size of a bitmap is governed by the memory available to the
application. Even in the best possible case of an application with very
little used resources, the address space is limited so as you fill it up (2
gigs max for a 32 bit process I think) the maximum you can allocate is
reduced.
The bitmap you quote is about 67.2 megs uncompressed.

Signature
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
> When I use the following code in a web page it works fine until my
> Bitmap size gets to a certain size, e.g. 5214 x 3223. Then I get a red
[quoted text clipped - 16 lines]
> objGraphics.Dispose()
> objBitmap.Dispose()
Norman Diamond - 10 Apr 2008 01:14 GMT
One limit is that the DotNet framework refuses to create an object of size
greater than 2GB, even in 64-bit versions of Windows. However, you haven't
reached that limit.
There can also be trouble with fragmentation of the virtual address space.
One of the biggest offenders here is the DLL that shows common dialog boxes
to let the user specify a file to be opened or saved. That DLL was given a
base address that is unlikely to conflict with other DLLs, so the DLL
doesn't need to be rebased when loaded, and that saves some number of
microseconds when loading the DLL. However, it's right smack in the middle
of the process's virtual address space. So after that DLL is loaded you
can't even create an object of size 1GB. This should be a lot less of a
problem in 64-bit versions of Windows.
> When I use the following code in a web page it works fine until my
> Bitmap size gets to a certain size, e.g. 5214 x 3223. Then I get a red
[quoted text clipped - 16 lines]
> objGraphics.Dispose()
> objBitmap.Dispose()