Console: Change resolution of all images in multipage TIFF file.

Code samples for VintaSoft Imaging .NET SDK. Here you can request a code sample.

Moderator: Alex

Post Reply
Alex
Site Admin
Posts: 2300
Joined: Thu Jul 10, 2008 2:21 pm

Console: Change resolution of all images in multipage TIFF file.

Post by Alex »

Here is C# code snippet that allows to change resolution of all images in TIFF file and save changes to the source TIFF file:

Code: Select all

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            // open file stream
            using (System.IO.FileStream fs = new System.IO.FileStream("multipage.tif", System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite))
            {
                // create image collection
                using (Vintasoft.Imaging.ImageCollection images = new Vintasoft.Imaging.ImageCollection())
                {
                    // add images from file stream to the image collection
                    images.Add(fs);

                    // for each image in image collection
                    for (int i = 0; i < images.Count; i++)
                    {
                        // change image resolution
                        images[i].Resolution = new Vintasoft.Imaging.Resolution(200, 200);
                    }

                    // create TIFF encoder
                    Vintasoft.Imaging.Codecs.Encoders.TiffEncoder encoder = new Vintasoft.Imaging.Codecs.Encoders.TiffEncoder();
                    // specify that TIFF encoder must save image collection to the source file and switch image collection to the saved file
                    encoder.SaveAndSwitchSource = true;

                    // save image collection to the source TIFF file
                    images.SaveSync(fs, encoder);
                }
            }
        }
    }
}
Post Reply