VintaSoft Imaging .NET SDK v8.6
Vintasoft.Imaging Namespace / ImageCollection Class / ImageSaving Event
Example



In This Topic
    ImageSaving Event (ImageCollection)
    In This Topic
    Occurs when image from this image collection is saving.
    Syntax
    'Declaration
     
    Public Event ImageSaving As EventHandler(Of ImageSavingEventArgs)
    public event EventHandler<ImageSavingEventArgs> ImageSaving
    public: __event EventHandler<ImageSavingEventArgs*>* ImageSaving
    public:
    event EventHandler<ImageSavingEventArgs^>^ ImageSaving
    Event Data

    The event handler receives an argument of type ImageSavingEventArgs containing data related to this event. The following ImageSavingEventArgs properties provide information specific to this event.

    PropertyDescription
    Gets or sets a value indicating whether current saving process should be canceled.  
    Gets the VintasoftImage object. (Inherited from Vintasoft.Imaging.ImageEventArgs)
    Remarks
    This event can occur if image collection is saving synchronously (SaveSync(Stream,EncoderBase)) or asynchronously (SaveAsync(Stream,EncoderBase)).
    Example
    This example demonstrates 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: Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also