VintaSoft Imaging .NET SDK and Plug-ins Discussions

Questions, comments and suggestions concerning VintaSoft Imaging .NET SDK.

Board index < VintaSoft Imaging < VintaSoft Imaging .NET SDK and Plug-ins Discussions

We are migrating to new forums engine, no new registration or posting currently available. TIA for your patience.

Save Multipage Tiff



Save Multipage Tiff

Post by montapas »

Hi,
I want to load an multipage Tiff and split this image in multi page tiff. (Example : I have a 100 pages tiff, I want to divided this into 10 files each file contains 10 pages.)
My Problem is that If I put a messagebox after one file saved then it is working fine. But if I ommit the message box it is generating multipage tiff.
I am using demo version.
Here is my sample code:
  _tiff = new TiffFile(openFileDialog1.FileName);
 outputFileName = sourceDirectory + splitFolder + "\\" + firstIndex.ToString()+ ".tif";

                    EncoderBase encoder = AvailableEncoders.FindEncoder(outputFileName);
                    VintasoftImage image1 = new VintasoftImage();
                    
                    ((TiffEncoder)encoder).CreateNewFile = true;
                    ((TiffEncoder)encoder).Compression = TiffCompression.JPEG;
                    ImageCollection images = new ImageCollection();
                    images.ImageSaving += new ImageSavingEventHandler(images_ImageSaving);
                    images.ImageSaved += new ImageSavedEventHandler(images_ImageSaved); 

                    for (int i = firstIndex; i <= lastIndex; i++)
                    {
                        images.Add(_tiff.Pages[i].GetImage());
                    }
                   
                    images.Save(outputFileName, (TiffEncoder)encoder);
                 //   MessageBox.Show("ok");
                    this.label1.Text = barcodeValue + ".tif saved Successfully";
                  //  System.Threading.Thread.SpinWait(5000);
                    //System.Threading.Thread test = System.Threading.Thread.CurrentThread;

                    
                    images.Dispose();
                   images = null;

Please help.

This is very urgent.

With Thanks,

Tapas


Re: Save Multipage Tiff

Post by Alex »

Hello Tapas,

Here is the best code:
TiffFile source = new TiffFile(openFileDialog1.FileName);

int pagesPerFile = 10, currentPagesPerFile = 0;
TiffFile dest = new TiffFile(sourceDirectory + splitFolder + @"\0.tif");
dest.Compression = TiffCompression.JPEG;
int fileIndex = 1;
for (int i = 0; i < source.Pages.Count; i++)
{
   dest.Pages.Add(source.Pages[i].GetImage());

   if (currentPagesPerFile == (pagesPerFile - 1))
   {
      dest.Dispose();
      dest = new TiffFile(sourceDirectory + splitFolder + "\\" + fileIndex + ".tif");
      dest.Compression = TiffCompression.JPEG;
      fileIndex++;
      currentPagesPerFile = 0;
   }
   else
   {
      currentPagesPerFile++;
   }
}

dest.Dispose();
source.Dispose();
Best regards, Alexander


Page 1 from 1: 1