Save Multipage Tiff

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

Moderator: Alex

Post Reply
montapas
Posts: 2
Joined: Mon Oct 12, 2009 10:29 am

Save Multipage Tiff

Post by montapas » Thu Oct 22, 2009 8:34 am

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:

Code: Select all

  _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

Alex
Site Admin
Posts: 1443
Joined: Thu Jul 10, 2008 2:21 pm

Re: Save Multipage Tiff

Post by Alex » Thu Oct 22, 2009 1:24 pm

Hello Tapas,

Here is the best code:

Code: Select all

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

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest