Cannot access a disposed object Object name: 'ImageMagick.MagickImage'

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
jinonline
Posts: 4
Joined: 2015-12-17T08:57:15-07:00
Authentication code: 1151

Cannot access a disposed object Object name: 'ImageMagick.MagickImage'

Post by jinonline »

HI.
i have a problem
when i build a gif , i get the error message
Cannot access a disposed object Object name: 'ImageMagick.MagickImage'

Code: Select all

using (MagickImageCollection collection = new MagickImageCollection())
{
      //combine image to MagickImage type
      for (var i = 1; i <= 6; i++)
      {
          //combine three image to single image
          using (MagickImageCollection images = new MagickImageCollection())
          {
              MagickImage image1 = new MagickImage(context.Server.MapPath("./template/background.png")); //background image
              images.Add(image1);

              MagickImage image2 = new MagickImage(UserBitmapData); //user image
              images.Add(image2);

              MagickImage image3 = new MagickImage(context.Server.MapPath("./template/front.png")); //front image
              images.Add(image3);

              using (MagickImage result = images.Mosaic())
              {
                  //add combine result to gif collection
                  collection.Add(result);
                  collection[i-1].AnimationDelay = 0;
              }
          }
      }

      // Optionally reduce colors
      QuantizeSettings settings = new QuantizeSettings();
      settings.Colors = 256;
      collection.Quantize(settings);

      collection.Optimize();

      // Save gif
      collection.Write(context.Server.MapPath("done.gif"));
}
jinonline
Posts: 4
Joined: 2015-12-17T08:57:15-07:00
Authentication code: 1151

Re: Cannot access a disposed object Object name: 'ImageMagick.MagickImage'

Post by jinonline »

I solved the problem, thanks XD

collection.Add(images.Mosaic());
collection[i-1].AnimationDelay = 0;
Post Reply