0

Exception Details: System.ArgumentException: Parameter is not valid.

Bitmap result = new Bitmap(7016, 9921);

Part of the method:

public Bitmap ResizeBitmap(Bitmap b, int nWidth, int nHeight)
{
    Bitmap result = new Bitmap(nWidth, nHeight);

nWidth and nHeight have thrown this same error, so I replaced it with explicit values and still the same error, it seems to work for smaller numbers though, but:

http://msdn.microsoft.com/en-us/library/7we6s1x3.aspx

Doesn't seem to indicate there is any limit? I've tried:

Bitmap result = new Bitmap(nWidth, nHeight);
Bitmap result = new Bitmap(7016, 9921);
Bitmap result = new Bitmap((int)7016, (int)9921);

All fail the same way.

Tom Gullen
  • 61,249
  • 84
  • 283
  • 456
  • 4
    similar: http://stackoverflow.com/questions/6333681/c-parameter-is-not-valid-creating-new-bitmap – AakashM Jul 11 '11 at 08:52
  • The exception occurs due the available memory. Piotr has probably more memory. – RvdK Jul 11 '11 at 08:54
  • Check this http://stackoverflow.com/questions/5801652/bitmap-while-assigning-height-width-crashes/5802113#5802113.. similar to what you have now – V4Vendetta Jul 11 '11 at 08:54
  • You do know you're trying to allocate about 280 megabytes, right? Try smaller sizes to see if you can find a limit. – Jason Goemaat Jul 11 '11 at 08:59

2 Answers2

2

I believe that there is just not enough memory to allocate bitmap.

treetey
  • 829
  • 1
  • 6
  • 16
  • How much memory will I need? Wouldn't that throw a different type of error? – Tom Gullen Jul 11 '11 at 08:55
  • ~265.5 MB. But note that it should be the continuous part of memory. Also you can change BPP value from 32 to 24 or 16 - it will require less memory. – treetey Jul 11 '11 at 08:59
0

That error occurs when you do not have the available memory to allocate such large of a block.

Admittedly, it's not a very good error message, and I'm not sure why Microsoft chose this error message rather than an OutOfMemory exception, but that's what happens.

foxy
  • 7,599
  • 2
  • 30
  • 34