Memory error saving collection

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
stoneyowl
Posts: 1
Joined: 2019-06-05T13:00:15-07:00
Authentication code: 1152

Memory error saving collection

Post by stoneyowl » 2019-06-05T13:06:39-07:00

I am developing a product that uses ImageMagick.Net as a screen capture video mechanism. I grab bmp images from a panel and pass the list of bitmaps to the 'MagickImageCollection' instance. Then the collection is optimized, color reduced andwritten to disk. This works up to a point, but I am getting this error: "memory allocation failed `C:\Temp\PRO_Engine_New.gif' @ error/quantize.c/QuantizeImage/2711" after around 40 or 50 bitmaps.

Source code in question is:

Code: Select all

        using (MagickImageCollection collection = new MagickImageCollection())
         {
            for (int i = 0; i < video.Count; i++)
            {
               Bitmap bmp = video[i];
               MagickImage img = new MagickImage(bmp);
               //img.Resample(600, 400);
               collection.Add(img);
               collection[collection.Count - 1].AnimationDelay = 150;
               collection[collection.Count - 1].AnimationIterations = 1;

               tsProgress.Value++;
               Application.DoEvents();
            }

            // Optionally reduce colors
            try
            {
               QuantizeSettings settings = new QuantizeSettings();
               settings.Colors = 128;
               collection.Quantize(settings);
               collection.Optimize();
               tsProgress.Value++;
               Application.DoEvents();
            }
            catch (Exception)
            {
               // do not reduce colors
            }
            // Optionally optimize the images (images should have the same size).

            // Save gif
            collection.Write(filename);
         }
What am I doing wrong here? I have 32GB of RAM and a little over 2 TB of SSD space.

Post Reply