VintaSoft Imaging .NET SDK 12.4: Documentation for .NET developer
In This Topic
    How to save image with the same encoder settings?
    In This Topic
    Sometimes it is necessary to load an image from file, change the image and save changed image to a file with the settings, which was used for encoding the source image.

    SDK allows to get the settings, which was used for encoding an image, using the following methods:
    Here is C#/VB.NET code that shows how to save image with the same encoder settings which was used for encoding source image:
    // open a TIFF file
    using (System.IO.FileStream fStream = new System.IO.FileStream(
         "multipage.tif",
         System.IO.FileMode.Open,
         System.IO.FileAccess.ReadWrite))
    {
        // create an image collection
        Vintasoft.Imaging.ImageCollection images =
            new Vintasoft.Imaging.ImageCollection();
        // add images from the stream to the image collection
        images.Add(fStream);
    
        // rotate the second page of TIFF file
        images[1].Rotate(90);
    
        // create a TIFF encoder
        using (Vintasoft.Imaging.Codecs.Encoders.EncoderBase encoder =
            Vintasoft.Imaging.Codecs.Encoders.AvailableEncoders.CreateEncoder("multipage.tif"))
        {
            // specify that encoder must switch the image source to the saved file
            encoder.SaveAndSwitchSource = true;
            // set the encoder settings similar to the settings, which was used for encoding the first page of TIFF file
            encoder.SetSettingsFromImage(images[0]);
            // save changes to the TIFF file
            images.SaveSync(fStream, encoder);
        }
    
        // clear the image collection and dispose the images
        images.ClearAndDisposeItems();
    }
    
    ' open a TIFF file
    Using fStream As New System.IO.FileStream("multipage.tif", System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite)
        ' create an image collection
        Dim images As New Vintasoft.Imaging.ImageCollection()
        ' add images from the stream to the image collection
        images.Add(fStream)
    
        ' rotate the second page of TIFF file
        images(1).Rotate(90)
    
        ' create a TIFF encoder
        Using encoder As Vintasoft.Imaging.Codecs.Encoders.EncoderBase = Vintasoft.Imaging.Codecs.Encoders.AvailableEncoders.CreateEncoder("multipage.tif")
            ' specify that encoder must switch the image source to the saved file
            encoder.SaveAndSwitchSource = True
            ' set the encoder settings similar to the settings, which was used for encoding the first page of TIFF file
            encoder.SetSettingsFromImage(images(0))
            ' save changes to the TIFF file
            images.SaveSync(fStream, encoder)
        End Using
    
        ' clear the image collection and dispose the images
        images.ClearAndDisposeItems()
    End Using