VintaSoft Imaging .NET SDK v8.7
Vintasoft.Imaging Namespace / ImageCollection Class / SaveAsync Method / SaveAsync(String) Method
Filename where the image collection should be saved.
Example



In This Topic
    SaveAsync(String) Method
    In This Topic
    Saves asynchronously all images from this collection to specified multipage image (JBIG2/PDF/TIFF) file.
    Syntax
    'Declaration
     
    Public Overloads Sub SaveAsync( _
       ByVal filename As String _
    ) 
    public void SaveAsync( 
       string filename
    )
    public: void SaveAsync( 
       string* filename
    ) 
    public:
    void SaveAsync( 
       String^ filename
    ) 

    Parameters

    filename
    Filename where the image collection should be saved.
    Exceptions
    ExceptionDescription
    Thrown if filename is null.
    Thrown if image collection does not contain images or another saving process is executing at this moment.
    Thrown if error occurs at saving the image.
    Remarks
    This method works asynchronously, i.e. separate thread is created for saving images.
    Supported image formats: JBIG2, PDF, TIFF.

    Suitable encoder is selected automatically from the extension of the filename, exception is thrown if encoder is not found for file extension specified in filename.

    This method
    • saves images to new JBIG2/PDF/TIFF file specified by filename
    • file specified by filename is overwritten if it exists
    • saving process can be canceled, saving of images can be suppressed
    • sources of images in the image collection are not changed, i.e. images[i].SourceInfo.Filename is not changed
    if
    • filename != images[0]..SourceInfo.Filename
    • SaveAndSwitchSource is false
    • createNewFile is true

    This method
    • saves images to new JBIG2/PDF/TIFF file specified by filename
    • file specified by filename is overwritten if it exists, value of the createNewFile parameter is ignored
    • saving process cannot be canceled, saving of images cannot be suppressed
    • sources of images in the image collection are changed, i.e. images[i].SourceInfo.Filename is changed to filename
    if
    This method
    • changes images in the source JBIG2/PDF/TIFF file if some images of source file are changed in the image collection
    • removes images from the source JBIG2/PDF/TIFF file if some images of source file are removed from the image collection
    • adds images to the source JBIG2/PDF/TIFF file if some images of NOT from the source file are added to the image collection
    • reindex images in the source JBIG2/PDF/TIFF file if images are reindexed in the image collection
    • file specified by filename is overwritten if it exists, value of the createNewFile parameter is ignored
    • saving process cannot be canceled, saving of images cannot be suppressed
    • sources of images in the image collection are changed, i.e. images[i].SourceInfo.Filename is changed to filename
    if
    This method
    • throw an exception
    if
    ImageSaving event will occur before saving of each image. In this event you can get information about the image, suppress image saving or cancel image saving process.
    ImageSaved event will occur after saving of each image. In this event you can get information about progress of images saving process or cancel image saving process.
    Example
    This example illustrates how to save the image collection asynchronously.
    ''' <summary>
    ''' Indicates whether image collection saving process is finished.
    ''' </summary>
    Private _isImagesSavingProcessFinished As Boolean = False
                
                
                
    ''' <summary>
    ''' Asynchronously saves an image collection to a file.
    ''' </summary>
    Public Sub ImageCollectionSaveAsyncExample()
    	' create image collection
    	Dim images As New Vintasoft.Imaging.ImageCollection()
                
    	' add several images into collection
    	' [ do not forget to set your image file paths here! ]
    	images.Add("testImage1.jpg")
    	images.Add("testImage2.bmp")
    	images.Add("testImage3.png")
                
    	' subscribe to the image collection events
    	AddHandler images.ImageCollectionSaving, New System.EventHandler(Of Vintasoft.Imaging.ImageCollectionSavingEventArgs)(AddressOf images_ImageCollectionSaving)
    	AddHandler images.ImageCollectionSavingProgress, New System.EventHandler(Of Vintasoft.Imaging.ProgressEventArgs)(AddressOf images_ImageCollectionSavingProgress)
    	AddHandler images.ImageCollectionSaved, New System.EventHandler(AddressOf images_ImageCollectionSaved)
    	AddHandler images.ImageSavingException, New System.EventHandler(Of Vintasoft.Imaging.ExceptionEventArgs)(AddressOf images_ImageSavingException)
    	AddHandler images.ImageCollectionSavingFinished, New System.EventHandler(AddressOf images_ImageCollectionSavingFinished)
                
    	_isImagesSavingProcessFinished = False
    	' start the asynchronously image collection saving
    	images.SaveAsync("new-file-name.tif")
                
    	' wait while image saving process will be finished
    	While Not _isImagesSavingProcessFinished
    		System.Threading.Thread.Sleep(1)
    	End While
    	
                
    End Sub
                
    ''' <summary>
    ''' Image collection saving process is started.
    ''' </summary>
    Private Sub images_ImageCollectionSaving(sender As Object, e As Vintasoft.Imaging.ImageCollectionSavingEventArgs)
    	System.Console.Write("Progress: ")
    End Sub
                
    ''' <summary>
    ''' Image collection saving process is in progress.
    ''' </summary>
    Private Sub images_ImageCollectionSavingProgress(sender As Object, e As Vintasoft.Imaging.ProgressEventArgs)
    	System.Console.Write(String.Format("{0}% ", e.Progress))
    End Sub
                
    ''' <summary>
    ''' Image collection is saved successfully.
    ''' </summary>
    Private Sub images_ImageCollectionSaved(sender As Object, e As System.EventArgs)
    	System.Console.WriteLine("Images are saved successfully.")
    End Sub
                
    ''' <summary>
    ''' Image collection is NOT saved.
    ''' </summary>
    Private Sub images_ImageSavingException(sender As Object, e As Vintasoft.Imaging.ExceptionEventArgs)
    	System.Console.WriteLine(e.Exception.Message)
    	System.Console.WriteLine("Images are NOT saved.")
    End Sub
                
    ''' <summary>
    ''' Image collection saving process is finished.
    ''' </summary>
    Private Sub images_ImageCollectionSavingFinished(sender As Object, e As System.EventArgs)
    	Dim images As Vintasoft.Imaging.ImageCollection = DirectCast(sender, Vintasoft.Imaging.ImageCollection)
                
    	' unsubscribe from image collection events
    	RemoveHandler images.ImageCollectionSaving, AddressOf images_ImageCollectionSaving
    	RemoveHandler images.ImageCollectionSavingProgress, AddressOf images_ImageCollectionSavingProgress
    	RemoveHandler images.ImageCollectionSaved, AddressOf images_ImageCollectionSaved
    	RemoveHandler images.ImageSavingException, AddressOf images_ImageSavingException
    	RemoveHandler images.ImageCollectionSavingFinished, AddressOf images_ImageCollectionSavingFinished
                
    	' indicate that image collection saving process is finished
    	_isImagesSavingProcessFinished = True
    End Sub
    /// <summary>
    /// Indicates whether image collection saving process is finished.
    /// </summary>
    bool _isImagesSavingProcessFinished = false;
                
                
                
    /// <summary>
    /// Asynchronously saves an image collection to a file.
    /// </summary>
    public void ImageCollectionSaveAsyncExample()
    {
        // create image collection
        Vintasoft.Imaging.ImageCollection images = new Vintasoft.Imaging.ImageCollection();
                
        // add several images into collection
        // [ do not forget to set your image file paths here! ]
        images.Add("testImage1.jpg");
        images.Add("testImage2.bmp");
        images.Add("testImage3.png");
                
        // subscribe to the image collection events
        images.ImageCollectionSaving +=
            new System.EventHandler<Vintasoft.Imaging.ImageCollectionSavingEventArgs>(images_ImageCollectionSaving);
        images.ImageCollectionSavingProgress += new System.EventHandler<Vintasoft.Imaging.ProgressEventArgs>(
            images_ImageCollectionSavingProgress);
        images.ImageCollectionSaved += new System.EventHandler(images_ImageCollectionSaved);
        images.ImageSavingException += new System.EventHandler<Vintasoft.Imaging.ExceptionEventArgs>(
            images_ImageSavingException);
        images.ImageCollectionSavingFinished += new System.EventHandler(images_ImageCollectionSavingFinished);
                
        _isImagesSavingProcessFinished = false;
        // start the asynchronously image collection saving
        images.SaveAsync("new-file-name.tif");
                
        // wait while image saving process will be finished
        while (!_isImagesSavingProcessFinished)
        {
            System.Threading.Thread.Sleep(1);
        };
    }
                
    /// <summary>
    /// Image collection saving process is started.
    /// </summary>
    private void images_ImageCollectionSaving(object sender, Vintasoft.Imaging.ImageCollectionSavingEventArgs e)
    {
        System.Console.Write("Progress: ");
    }
                
    /// <summary>
    /// Image collection saving process is in progress.
    /// </summary>
    private void images_ImageCollectionSavingProgress(object sender, Vintasoft.Imaging.ProgressEventArgs e)
    {
        System.Console.Write(string.Format("{0}% ", e.Progress));
    }
                
    /// <summary>
    /// Image collection is saved successfully.
    /// </summary>
    private void images_ImageCollectionSaved(object sender, System.EventArgs e)
    {
        System.Console.WriteLine("Images are saved successfully.");
    }
                
    /// <summary>
    /// Image collection is NOT saved.
    /// </summary>
    private void images_ImageSavingException(object sender, Vintasoft.Imaging.ExceptionEventArgs e)
    {
        System.Console.WriteLine(e.Exception.Message);
        System.Console.WriteLine("Images are NOT saved.");
    }
                
    /// <summary>
    /// Image collection saving process is finished.
    /// </summary>
    private void images_ImageCollectionSavingFinished(object sender, System.EventArgs e)
    {
        Vintasoft.Imaging.ImageCollection images = (Vintasoft.Imaging.ImageCollection)sender;
                
        // unsubscribe from image collection events
        images.ImageCollectionSaving -= images_ImageCollectionSaving;
        images.ImageCollectionSavingProgress -= images_ImageCollectionSavingProgress;
        images.ImageCollectionSaved -= images_ImageCollectionSaved;
        images.ImageSavingException -= images_ImageSavingException;
        images.ImageCollectionSavingFinished -= images_ImageCollectionSavingFinished;
                
        // indicate that image collection saving process is finished
        _isImagesSavingProcessFinished = true;
    }
    Requirements

    Target Platforms: Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also