Free Support Forum - aspose.com

Saving TIFF - Overwrite existing file with Options

When I execute the following code and fpDest already exists, the new file does not save. There is a Save function that has an overwrite parameter, but I do not see one that can be used with Options. How do I get the file to overwrite when using Options?

            using (var image = Image.Load(fpSource, new LoadOptions() { BufferSizeHint = 50 }))
            {
                // perform Rotate operation
                ((RasterImage)image).Rotate(nDegrees); // rotate 60 degrees clockwise
                ImageOptionsBase io= image.GetOriginalOptions();
                TiffOptions outputSettings = new TiffOptions(TiffExpectedFormat.Default);
                outputSettings.BitsPerSample = new ushort[] { (ushort)image.BitsPerPixel };
                
                if (image.BitsPerPixel != 1) // Color                
                {
                    outputSettings.Compression = TiffCompressions.Lzw;
                    if (image.BitsPerPixel == 8)
                        outputSettings.Palette = ColorPaletteHelper.Create8Bit();
                    else
                        outputSettings.Palette = ColorPaletteHelper.Create4Bit();
                    outputSettings.Photometric = TiffPhotometrics.Palette;
                }
                else
                    outputSettings.Compression = TiffCompressions.CcittFax4;
                ResolutionSetting res = new ResolutionSetting(300, 300);  // 300 x 300 DPI                    
                outputSettings.ResolutionSettings = res;
                image.Save(fpDest, outputSettings);

Never mind. Sorry! I just realized that I can do something like this:

            using (FileStream outputStream = new FileStream(fpDest, FileMode.Create, FileAccess.Write))

            {
                image.Save(outputStream, outputSettings);
            }

@yangh1,

It’s good to hear that you have figured it out on your end.