Start from memory resizing of the image in the grid of points

I am having a lot of problems causing images to resize. At first I was sure that I was just leaking, so I switched my own code to something based on https://github.com/JimBobSquarePants/ImageProcessor and the same problems occur.

So the original image causing the problem might be 7137x10096 Uncompressed, which should be 7137x10096x4 = 288220608 bytes or 274 MB. Okay, this is "big", but why is this a concern? Running it, IISExpress (32 bit) throws it out of memory. Running on Azure on a 64-bit server with 3.5 GB is simply unreliable.

Error: "An exception of type 'System.OutOfMemoryException' occurred in System.Drawing.dll but was not handled in user code"

ImageProcessor based code issue imageFactory.Load command

   public bool ProcessStream(Size size, Func<MemoryStream, bool> resultCallback, string gravity, Stream inStream, int quality=80)
    {
        inStream.Position = 0;
        bool res = false;
        using (var outStream = new MemoryStream())
        {
            using (var imageFactory = new ImageFactory())
            {
                var anchor = AnchorPosition.Center;
                if (gravity == "top") anchor = AnchorPosition.Top;
                if (gravity == "bottom") anchor = AnchorPosition.Bottom;
                var layer = new ResizeLayer(size, ResizeMode.Pad, anchor);

                imageFactory.Load(inStream)
                    .Resize(layer)
                    .BackgroundColor(System.Drawing.ColorTranslator.FromHtml("#FFFFFF"))
                    .Quality(quality)
                    .Save(outStream);
                res = resultCallback(outStream);
            }
        }
        return res;
    }

      

In my simplest test case, I call this with

     public bool nop(MemoryStream s)
     {
         return true;
     }

     public string TestResize()
     {
         var resizer = new ResizeImage();
         var size = new System.Drawing.Size(300, 400);
         using (
             var filestream =
                 new FileStream(
                     @"C:\Users\Andrew\problem issues\NastyLargeImageThatBreaksThings.jpg",
                     FileMode.Open, FileAccess.Read))
         {
             var res = resizer.ProcessStream(size, nop, "top", filestream, 75);
             return res.ToString();
         }
     }

      

I can:

1) Try another method

2) Upgrade my Azure servers to have more memory (not sure if this helps)

3) Try resizing with a third party service like http://www.blitline.com/ that has some Azure integration.

Any insight as to why images of this size cannot be processed in Systen.Drawing would be much appreciated.

+3
c # out-of-memory azure system.drawing imageprocessor


source to share


No one has answered this question yet

Check out similar questions:

1207
Strange memory issue when loading image into Bitmap object
805
How do I get a .NET application to run under administrator control?
390
Difference between ref and out parameters in .NET.
261
In .NET, which loop is faster, "for" or "foreach"?
254
How to resize an image C #
187
Node.js heap from memory
138
How does the .NET framework allocate memory for an OutOfMemoryException?
74
.NET Out Of Memory Exception - 1.3 GB in use but 16 GB installed
48
C #: out of memory exception
0
System.Drawing.Image.FromFile "System.OutOfMemoryException: Out of memory."



All Articles
Loading...
X
Show
Funny
Dev
Pics