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

Free Support Forum - aspose.com

Tiff Splitting Result Is Being Deleted On Dispose

Using the following code, to split a multipage tiff into single pages, I find see a file created when File.Create is called but after the save and then the exit of the using the file is deleted. Why is the file being removed on the dispose? How do I prevent this?


using (var multiImage = (TiffImage) Image.Load(@“Resources\Multi.tiff”))
{
var frameCounter = 0;
foreach (var tiffFrame in multiImage.Frames)
{
multiImage.ActiveFrame = tiffFrame;
var pixels = multiImage.LoadPixels(tiffFrame.Bounds);
var createOptions = new TiffOptions();
createOptions.Compression = TiffCompressions.CcittFax4;
createOptions.BitsPerSample = new ushort[] {1};
createOptions.Photometric = TiffPhotometrics.MinIsWhite;
createOptions.Source = new FileCreateSource(frameCounter.ToString(“0000”) + “.tiff”);

using (var tiffImage = (TiffImage) Image.Create(createOptions, tiffFrame.Width, tiffFrame.Height))
{
tiffImage.SavePixels(tiffFrame.Bounds, pixels);
tiffImage.Save();
}
frameCounter++;
}
}

Hi Michael,


Thank you for contacting Aspose support.

The presented scenario is caused due to the default behavior of FileCreateSource class. If you are not passing the second parameter (isTemporal) to the constructor of aforesaid class or specifying isTemporal as true, the newly saved files will be automatically deleted from the local disk. You can avoid this situation by passing false as demonstrated below.

C#

using (var multiImage = (TiffImage)Image.Load(“D:/temp/merged-by-Aspose-copy.tiff”))
{
var frameCounter = 0;
foreach (var tiffFrame in multiImage.Frames)
{
multiImage.ActiveFrame = tiffFrame;
var pixels = multiImage.LoadPixels(tiffFrame.Bounds);

var createOptions = new TiffOptions();
createOptions.Compression = TiffCompressions.CcittFax4;
createOptions.BitsPerSample = new ushort[] { 1 };
createOptions.Photometric = TiffPhotometrics.MinIsWhite;
createOptions.Source = new FileCreateSource(frameCounter.ToString(“0000”) + “.tiff”, false);

using (var tiffImage = (TiffImage)Image.Create(createOptions, tiffFrame.Width, tiffFrame.Height))
{
tiffImage.SavePixels(tiffFrame.Bounds, pixels);
tiffImage.Save();
}
frameCounter++;
}
}

Please feel free to write back in case you need our further assistance with Aspose APIs.

My mistake thanks for your help.