VintaSoft Imaging .NET SDK 15.1: Documentation for .NET developer
Vintasoft.Imaging Namespace / ImageCollection Class / ImageSaving Event
Syntax Remarks Example Requirements SeeAlso
In This Topic
ImageSaving Event (ImageCollection)
In This Topic
Occurs when image from this image collection is saving.
Syntax
Remarks

This event can occur if image collection is saving synchronously (SaveSync(Stream,EncoderBase)) or asynchronously (SaveAsync(Stream,EncoderBase)).

Example

This C#/VB.NET code shows how to merge some image files into one TIFF or PDF file and get status of the saving process.


Class ImageCollectionEncoder

    Private _filename As String
    Private _pageIndex As Integer

    ''' <summary>
    ''' Merges some image files into one TIFF or PDF file.
    ''' </summary>
    ''' <param name="inFilenames"></param>
    ''' <param name="outFilename"></param>
    Public Sub MergeImageFilesSynchronously(inFilenames As String(), outFilename As String)
        Dim images As New Vintasoft.Imaging.ImageCollection()
        AddHandler images.ImageSaving, New System.EventHandler(Of Vintasoft.Imaging.ImageSavingEventArgs)(AddressOf _images_ImageSaving)
        AddHandler images.ImageSaved, New System.EventHandler(Of Vintasoft.Imaging.ImageEventArgs)(AddressOf _images_ImageSaved)

        For Each filename As String In inFilenames
            If filename Is Nothing Then
                Exit For
            End If

            ' add images from file to image collection
            images.Add(filename)
        Next

        Try
            ' save images from image collection to the output file
            images.SaveSync(outFilename)
        Catch ex As Vintasoft.Imaging.Codecs.Encoders.TiffEncoderException
            System.Console.WriteLine("Saving error: Filename={0}, PageIndex={1}, ErrorMessage={2}", _filename, _pageIndex, ex.Message)
            System.Console.ReadKey()
        End Try

        ' clear image collection
        images.ClearAndDisposeItems()
    End Sub

    Private Sub _images_ImageSaving(sender As Object, e As Vintasoft.Imaging.ImageSavingEventArgs)
        _filename = e.Image.SourceInfo.Filename
        _pageIndex = e.Image.SourceInfo.PageIndex

        System.Console.WriteLine("Image saving: Filename={0}, PageIndex={1}", _filename, _pageIndex)
    End Sub

    Private Sub _images_ImageSaved(sender As Object, e As Vintasoft.Imaging.ImageEventArgs)
        System.Console.WriteLine("Image saved: Filename={0}, PageIndex={1}", _filename, _pageIndex)
    End Sub

End Class


class ImageCollectionEncoder
{

    string _filename;
    int _pageIndex;

    /// <summary>
    /// Merges some image files into one TIFF or PDF file.
    /// </summary>
    /// <param name="inFilenames"></param>
    /// <param name="outFilename"></param>
    public void MergeImageFilesSynchronously(string[] inFilenames, string outFilename)
    {
        Vintasoft.Imaging.ImageCollection images = new Vintasoft.Imaging.ImageCollection();
        images.ImageSaving += new System.EventHandler<Vintasoft.Imaging.ImageSavingEventArgs>(_images_ImageSaving);
        images.ImageSaved += new System.EventHandler<Vintasoft.Imaging.ImageEventArgs>(_images_ImageSaved);

        foreach (string filename in inFilenames)
        {
            if (filename == null)
                break;

            // add images from file to image collection
            images.Add(filename);
        }

        try
        {
            // save images from image collection to the output file
            images.SaveSync(outFilename);
        }
        catch (Vintasoft.Imaging.Codecs.Encoders.TiffEncoderException ex)
        {
            System.Console.WriteLine(
                "Saving error: Filename={0}, PageIndex={1}, ErrorMessage={2}", _filename, _pageIndex, ex.Message);
            System.Console.ReadKey();
        }

        // clear image collection
        images.ClearAndDisposeItems();
    }

    private void _images_ImageSaving(object sender, Vintasoft.Imaging.ImageSavingEventArgs e)
    {
        _filename = e.Image.SourceInfo.Filename;
        _pageIndex = e.Image.SourceInfo.PageIndex;

        System.Console.WriteLine("Image saving: Filename={0}, PageIndex={1}", _filename, _pageIndex);
    }

    private void _images_ImageSaved(object sender, Vintasoft.Imaging.ImageEventArgs e)
    {
        System.Console.WriteLine("Image saved: Filename={0}, PageIndex={1}", _filename, _pageIndex);
    }

}

Requirements

Target Platforms: .NET 10; .NET 9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

See Also