We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

TiffImage.Save causing System.ObjectDisposedException

I was unable to open a paid support ticket even though we pay for support.

I’m using the following code:

        public ConversionResult ConvertAndEmbed()
    {
        var ic = new ImgConverter(_creq,_cres);

        var tiffOptions = new TiffOptions(TiffExpectedFormat.TiffCcittFax4)
        {
            Compression = TiffCompressions.CcittFax4,
            Photometric = TiffPhotometrics.MinIsWhite,
            

            ResolutionSettings = new ResolutionSetting
            {
                HorizontalResolution = _creq.Resolution,
                VerticalResolution = _creq.Resolution
            },
            
        };
        

        var insertImage = ic.ConvertToTiff(_creq.SourcBytes);
        int height = _creq.Height;
        int width = _creq.Width;

        try
        {

            //Now we have a Group 4 Fax tiff
            using (var inMs = new MemoryStream(insertImage))
            using (var outMs = new MemoryStream())
            using (TiffImage image = (TiffImage) Image.Load(inMs))
            {
                tiffOptions.Source = new Aspose.Imaging.Sources.StreamSource(new MemoryStream());
                using (TiffImage tiffImage = (TiffImage)Image.Create(tiffOptions, width, height))
                {
                    for (int ctr = 0; ctr < image.Frames.Length; ctr++)
                    {

                        image.ActiveFrame = image.Frames[ctr];
                        if (height == 0) height = image.ActiveFrame.Height;
                        if (width == 0) width = image.ActiveFrame.Width;
                        image.ResizeWidthProportionally(width, ResizeType.NearestNeighbourResample);

                        if (ctr == 0)
                        {
                            tiffImage.ActiveFrame.SavePixels(image.ActiveFrame.Bounds,
                                image.LoadPixels(image.ActiveFrame.Bounds));
                        }
                        else
                        {
                            using (var frame = new TiffFrame(tiffOptions, width, height))
                            {
                                frame.SavePixels(image.ActiveFrame.Bounds, image.LoadPixels(image.ActiveFrame.Bounds));
                                TiffFrame newFrame = TiffFrame.CopyFrame(frame);
                                tiffImage.AddFrame(newFrame);
                                tiffImage.Save();
                            }
                        }
                    }

                    tiffImage.Save(outMs, tiffOptions);
                    _cres.Contents.Add(outMs.ToArray());
                }
            }
        }
        catch (Exception e)
        {
            _cres.IsError = true;
            _cres.Error = "Error in ConvertToTiffAndEmbed " + e.Message;
        }

        return _cres;
    }

The tiffImage.Save(); is causing System.ObjectDisposedException. It is ok with just 2 frames but if I add a third frame it errors.

Tom

@tom.beadle,

I have observed the sample code shared by you and request you to please share the source image reproducing the issue on your end. I also suggest you to please try using Aspose.Imaging for .NET 17.9 as well on your end before sharing further information with us.

You may please visit Paid Support section to log request. If you still face any issue then please share with us.