TIFF: How to add image collection to TIFF file?
In This Topic
Image collection can be added to TIFF file by several ways.
Here is C#/VB.NET code that shows how to synchronously add non black-white images from image collection to TIFF file using TiffEncoder class:
public void AddImagesToTiff(System.IO.Stream stream, Vintasoft.Imaging.ImageCollection images)
{
// add images to TIFF file
using (Vintasoft.Imaging.Codecs.Encoders.TiffEncoder encoder =
new Vintasoft.Imaging.Codecs.Encoders.TiffEncoder(false))
{
// use LZW compression
encoder.Settings.Compression = Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Lzw;
// add images to TIFF file
encoder.SaveImages(images, stream);
}
}
Public Sub AddImagesToTiff(stream As System.IO.Stream, images As Vintasoft.Imaging.ImageCollection)
' add images to TIFF file
Using encoder As New Vintasoft.Imaging.Codecs.Encoders.TiffEncoder(False)
' use LZW compression
encoder.Settings.Compression = Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Lzw
' add images to TIFF file
encoder.SaveImages(images, stream)
End Using
End Sub
Here is C#/VB.NET code that shows how to synchronously add non black-white images from image collection to TIFF file using TiffFile class:
public void AddImagesToTiff(System.IO.Stream stream, Vintasoft.Imaging.ImageCollection images)
{
// open existing TIFF file
using (Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFile tiff =
new Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFile(stream))
{
// use LZW compression
tiff.Pages.EncoderSettings.Compression = Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Lzw;
// for each image in image collection
for (int i = 0; i < images.Count; i++)
{
// do not save black-white images to TIFF file
if (images[i].BitsPerPixel == 1)
continue;
// add image to TIFF file
tiff.Pages.Add(images[i]);
// save changes
tiff.SaveChanges();
}
}
}
Public Sub AddImagesToTiff(stream As System.IO.Stream, images As Vintasoft.Imaging.ImageCollection)
' open existing TIFF file
Using tiff As New Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFile(stream)
' use LZW compression
tiff.Pages.EncoderSettings.Compression = Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Lzw
' for each image in image collection
For i As Integer = 0 To images.Count - 1
' do not save black-white images to TIFF file
If images(i).BitsPerPixel = 1 Then
Continue For
End If
' add image to TIFF file
tiff.Pages.Add(images(i))
' save changes
tiff.SaveChanges()
Next
End Using
End Sub
Here is C#/VB.NET code that shows how to synchronously add non black-white images from image collection to TIFF file using ImageCollection and TiffEncoder classes:
public void AddImagesToTiff(System.IO.Stream stream, Vintasoft.Imaging.ImageCollection images)
{
// add images to TIFF file
Vintasoft.Imaging.Codecs.Encoders.TiffEncoder encoder = new Vintasoft.Imaging.Codecs.Encoders.TiffEncoder(false);
// use LZW compression
encoder.Settings.Compression = Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Lzw;
// add images to TIFF file synchronously
images.SaveSync(stream, encoder);
// release resources used by encoder
encoder.Dispose();
}
Public Sub AddImagesToTiff(stream As System.IO.Stream, images As Vintasoft.Imaging.ImageCollection)
' add images to TIFF file
Dim encoder As New Vintasoft.Imaging.Codecs.Encoders.TiffEncoder(False)
' use LZW compression
encoder.Settings.Compression = Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Lzw
' add images to TIFF file synchronously
images.SaveSync(stream, encoder)
' release resources used by encoder
encoder.Dispose()
End Sub
Here is C#/VB.NET code that shows how to asynchronously add non black-white images from image collection to TIFF file using ImageCollection and TiffEncoder classes:
public void AddImagesToTiff(System.IO.Stream stream, Vintasoft.Imaging.ImageCollection images)
{
// add images to TIFF file
Vintasoft.Imaging.Codecs.Encoders.TiffEncoder encoder = new Vintasoft.Imaging.Codecs.Encoders.TiffEncoder(false);
// use LZW compression
encoder.Settings.Compression = Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Lzw;
// add images to TIFF file asynchronously
images.SaveAsync(stream, encoder);
}
Public Sub AddImagesToTiff(stream As System.IO.Stream, images As Vintasoft.Imaging.ImageCollection)
' add images to TIFF file
Dim encoder As New Vintasoft.Imaging.Codecs.Encoders.TiffEncoder(False)
' use LZW compression
encoder.Settings.Compression = Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Lzw
' add images to TIFF file asynchronously
images.SaveAsync(stream, encoder)
End Sub