0

After create newBitmap i m getting exception - Parameter is not valid , When i want to create 9000*9000 pixel image. I need to create big resolution image. I cant able to create big Image because of this error.

enter image description here

My RAM is 16 GB .My system is 64 bit. Sometime it occurs Out of memory also. How to solve this issue ?

Here is my code

 private  Bitmap createBigImage(Bitmap layerBitmap, int newWidth, int newHeight)
 {

            Bitmap newBitmap = new Bitmap(newWidth, newHeight, PixelFormat.Format32bppArgb);

                using (Graphics gr = Graphics.FromImage(newBitmap))
                {
                    gr.SmoothingMode = SmoothingMode.HighQuality;
                    gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
                    gr.DrawImage(layerBitmap, new Rectangle(0, 0, newWidth, newHeight));
                    gr.Dispose();

                }



           return newBitmap;

    }

   Bitmap newbitmap = createBigImage(bitmap, 9000, 9000);
sreejaya
  • 45
  • 1
  • 2
  • 11
  • http://www.asprangers.com/post/2012/03/23/Why-you-should-not-use-SystemDrawing-from-ASPNET-applications.aspx – Bauss Sep 07 '15 at 05:56
  • 1
    The real issue is probably that the instance of `newbitmap` is not disposed. However in what sense would you need a `9000x9000` image? I'm sure whatever you're trying to do can be done better. – Bauss Sep 07 '15 at 05:56
  • Should work reasonably fine in 64-bit process. Width of (9000*4byte-per-pixel) is not hitting 64K limit per line yet (http://stackoverflow.com/questions/6333681/c-sharp-parameter-is-not-valid-creating-new-bitmap). Could you please confirm that your code runs in 64-bit process? – Alexei Levenkov Sep 07 '15 at 05:59
  • I got the same `Parameter is not valid` error when I ran your code passing in a JPG file as the `bitmap` parameter. Putting in the full path name solved it. Perhaps you should look at your inputs? The size didn't seem to be an issue (I tried 10000). – Michael McMullin Sep 07 '15 at 06:15
  • At what line do you get the error? Full exception with stack trace? It is unclear that the issue is the size of bitmap.. or if it is something else? – Vikas Gupta Sep 07 '15 at 06:26
  • I am getting error in Bitmap newBitmap = new Bitmap(newWidth, newHeight, PixelFormat.Format32bppArgb); I can create 6000*6000 Image . – sreejaya Sep 07 '15 at 06:41
  • @sreejaya Are you calling createBigImage within a loop? I tried a quick test, and your method worked fine on its own. However, when I called it within a loop, it failed after 3 iterations. Calling `newbitmap.Dispose()` (as @Bauss suggested above) at the end of each loop eliminated the error. I'd guess it's a memory issue. – Michael McMullin Sep 07 '15 at 13:36
  • I tried this code without any loop and any other. I tried to call in page load itself and also tried different machine. I cant able to create an Image . Always exception is coming "Parameter is not valid". I have to do any specific settings in asp.net ? – sreejaya Sep 08 '15 at 05:59
  • My windows : Window7 Enterprise System Typ : 64 bit Os I tried in another system with 32 bit OS, that is working. Is it causing because of 64 bit OS ? – sreejaya Sep 08 '15 at 08:58

0 Answers0