Extract some pages to a new multipage tiff

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

Moderator: Alex

Post Reply
gunnuy
Posts: 2
Joined: Thu Sep 06, 2018 10:51 am

Extract some pages to a new multipage tiff

Post by gunnuy » Fri Sep 07, 2018 8:59 am

Hi,

trying to save some thumbnail viewer selected items into a new multipage TIFF file and deleting those from the
image collection, I simply don't get the clue.

Have some code sample for that issue?

Thank you and best regards

Guenther

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

Re: Extract some pages to a new multipage tiff

Post by Alex » Fri Sep 07, 2018 9:57 am

Hi Guenter,

Here is a code snippet that shows how to save images, which are selected in thumbnail viewer, to a TIFF file and remove saved images from thumbnail viewer:

Code: Select all

using System;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }



        private void Form1_Load(object sender, EventArgs e)
        {
            // add images to the thumbnail viewer
            thumbnailViewer1.Images.Add("DocCleanMultipage.tif");
        }

        private void saveImagesButton_Click(object sender, EventArgs e)
        {
            // create or open TIFF file
            using (System.IO.FileStream fs = new System.IO.FileStream("result.tif", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite))
            {
                // create TIFF encoder
                Vintasoft.Imaging.Codecs.Encoders.TiffEncoder tiffEncoder = new Vintasoft.Imaging.Codecs.Encoders.TiffEncoder();
                // specify that images must be added to the existing TIFF file
                tiffEncoder.CreateNewFile = false;

                // get the indices of thumbnails, which are selected in thumbnail viewer
                Vintasoft.Imaging.UI.IndicesCollection indicesCollection = thumbnailViewer1.SelectedIndices;
                // for each selected thumbnail
                foreach (int i in indicesCollection)
                {
                    // add image to the TIFF file
                    tiffEncoder.SaveImage(thumbnailViewer1.Images[i], fs);
                }

                // remove saved thumbnails from thumbnail viewer
                thumbnailViewer1.Images.RemoveRange(indicesCollection.ToArray());
            }
        }

    }
}
Best regards, Alexander

gunnuy
Posts: 2
Joined: Thu Sep 06, 2018 10:51 am

Re: Extract some pages to a new multipage tiff

Post by gunnuy » Mon Sep 10, 2018 7:58 am

That's great!

Thank you very much

Best Regards
Guenther

Post Reply