5

I get this exception:

System.ArgumentException occurred
Message="Parameter is not valid."
Source="System.Drawing"
StackTrace:
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height)...

when I instantiate a new Bitmap in this way:

Bitmap resImage = new Bitmap(width, height);
resImage.SetResolution(600, 600);

where width and height are the dimensions converted in pixel for 600 dpi of the size set by the user in cm, which is in this specific case 28x41 cm (A3 format image) corresponding to 6614x9685 pixel. After that I will create a graphics object from the bitmap and draw on it with the methods of GDI+. I need an high resolution image because it is going to be added to a pdf document and I want a great quality result.

I get this exception only if a call the method from a web application, that references the dll in which all the printing logic is written.

Why I obtain this exception? How can I solve the problem?

Thanks in advance for every help!

Nolonar
  • 5,962
  • 3
  • 36
  • 55
Sara
  • 97
  • 1
  • 6
  • What `Type` is `width` and `height`? – Mike Perrenoud Nov 06 '13 at 14:58
  • 2
    And what are the *values* of `width` and `height`? (Not what you expect them to be, but actual values shown via diagnostics...) – Jon Skeet Nov 06 '13 at 14:58
  • Possible duplicate of http://stackoverflow.com/questions/1949045/net-bitmap-class-constructor-int-int-and-int-int-pixelformat-throws-argu The accepted answer for that question mentions memory issues (getting at Jon's question) – Sven Grosen Nov 06 '13 at 15:00
  • The values that I've written in the question are the actual values shown via diagnostic and their type is Int32 as required by the Bitmap costructor. – Sara Nov 06 '13 at 16:01
  • Moreover, I think that the situation is different from that in the stackoverflow.com/questions/1949045/… because I get the exception only if I call the method from a web application, not if I launch it from a windows application – Sara Nov 06 '13 at 16:02
  • An image that size with the default pixel format (32 bpp) will occupy about 256 MB of memory. One possibility is that the Web app is running in 32 bit mode and you don't have a contiguous block of 256 MB free, but your client app does. Is your Web app a 32 bit process? – Jim Mischel Nov 06 '13 at 16:09
  • The app is built for mixed platform, but my computer is actually a 32 bit processor. Is this that cause the problem? And how can I solve it? I really need to be able to manage this kind of bitmaps with high resolution. – Sara Nov 08 '13 at 08:38
  • See also [this question](http://stackoverflow.com/questions/6333681/c-sharp-parameter-is-not-valid-creating-new-bitmap). – Dimitri C. Nov 06 '15 at 14:17

0 Answers0