-1

I am trying to create a picturebox of large size. I am able to create and draw Bitmap of size upto 8500x8500. But when I clear it and load another Bitmap of same size, it shows OutofMemoryException. I am running this on a DELL laptop with 8GB RAM and i7 processor.

Following is the code snippet:

pictureBox_MouseMove()
{
    //Draw some lines...
}

buttonClear_Click()
{
     Bitmap new_image = new Bitmap(8500,8500); // OutofMemoryException
}

I would also like to know how to allocate memory to these objects.

Thanks in advance.

Raj Kumar Mishra
  • 516
  • 4
  • 16
  • It's (nearly) not possible, because of GDI+ limitation http://stackoverflow.com/questions/29175585/what-is-the-maximum-resolution-of-c-sharp-net-bitmap –  Feb 14 '17 at 10:55
  • 1
    It is not a very good dup. Project > Properties > Build tab, untick the "Prefer 32-bit" checkbox. You don't prefer it when you manipulate big bitmaps, finding 276 megabytes of contiguous space in a 32-bit process only works right after your program starts, not after it has been running for a while and the address space got fragmented. Not a problem in a 64-bit process, lots and lots of space. You can go up to 2 gigabytes, roughly a 23000 x 23000 bitmap. – Hans Passant Feb 14 '17 at 12:38
  • Thanks Hans Passant...that really worked.. – Raj Kumar Mishra Feb 15 '17 at 11:10

1 Answers1

0

Seems that you are not disposed the old bitmap when new one is created. Try to call oldimage.Dispose() before creation of new Bitmap.

Andrii Shvydkyi
  • 2,236
  • 1
  • 14
  • 19
  • I tried this but still doesn't work. – Raj Kumar Mishra Feb 14 '17 at 11:02
  • Hm, if you could create it once you should be able to do it again, provided the old one is actually and really really really cleared, deleted, disposed of. Maybe some reference still hangs in there..? – TaW Feb 14 '17 at 12:35