SaveAsync(String,EncoderBase) Method (ImageCollection)
In This Topic
Saves asynchronously all images from this collection to specified multipage image (JBIG2/PDF/TIFF) file using the specified
EncoderBase.
Syntax
Parameters
- filename
- Filename where the image collection should be saved.
- encoder
- Encoder to the save images.
Exceptions
Remarks
This method works asynchronously, i.e. separate thread is created for saving images.
Supported image formats: JBIG2, PDF, TIFF.
This method
- saves images to new image file specified by filename using encoder
- 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 is not changed, i.e. images[i].SourceInfo.Filename is not changed
if
- filename != images[0]..SourceInfo.Filename
- SaveAndSwitchSource is false
- encoder.CreateNewFile is true
This method
- adds images to existing image file specified by filename using encoder
- 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
- encoder.CreateNewFile is false
This method
- saves images to new JBIG2/PDF/TIFF file specified by filename using encoder
- file specified by filename is overwritten if it exists
- 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
- saving process cannot be canceled, saving of images cannot be suppressed
- sources of images in the image collection is changed, i.e. images[i].SourceInfo.Filename is changed to filename
if
This method
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 and
''' switches image collection to the saved 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")
' create the TiffEncoder instance
Dim multipageEncoder As Vintasoft.Imaging.Codecs.Encoders.MultipageEncoderBase = New Vintasoft.Imaging.Codecs.Encoders.TiffEncoder()
' subscribe on 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
' save images to file and switch source
multipageEncoder.SaveAndSwitchSource = True
' save image collection asynchronously
images.SaveAsync("new-file-name.tif", multipageEncoder)
' wait while image saving process is 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 and
/// switches image collection to the saved 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");
// create the TiffEncoder instance
Vintasoft.Imaging.Codecs.Encoders.MultipageEncoderBase multipageEncoder =
new Vintasoft.Imaging.Codecs.Encoders.TiffEncoder();
// subscribe on 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;
// save images to file and switch source
multipageEncoder.SaveAndSwitchSource = true;
// save image collection asynchronously
images.SaveAsync("new-file-name.tif", multipageEncoder);
// wait while image saving process is 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: .NET9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
See Also