VintaSoft Imaging .NET SDK 12.4: Documentation for .NET developer
Vintasoft.Imaging.Codecs.Encoders Namespace / AvailableEncoders Class
Members Object Syntax Example Hierarchy Requirements SeeAlso
In This Topic
    AvailableEncoders Class
    In This Topic
    Contains static properties and methods that allow to get list of available encoders and find encoder for the image by using extension of filename.
    Object Model
    AvailableEncoders
    Syntax
    'Declaration
    
    Public MustInherit NotInheritable Class AvailableEncoders
    
    
    public static class AvailableEncoders
    
    
    public __gc abstract __sealed class AvailableEncoders
    
    
    public ref class AvailableEncoders abstract sealed
    
    
    Example

    Here is an example that shows how to get an encoder for specified filename, change the encoder's settings and save specified images to the file using encoder:

    
    ''' <summary>
    ''' Gets an encoder by the filename extension,
    ''' changes settings of the encoder and
    ''' saves an image collection to a file using encoder.
    ''' </summary>
    Public Shared Sub ChangeEncoderSettingsAndSave(images As Vintasoft.Imaging.ImageCollection, filename As String)
        ' get an encoder by the filename extension
        Dim encoder As Vintasoft.Imaging.Codecs.Encoders.EncoderBase = Vintasoft.Imaging.Codecs.Encoders.AvailableEncoders.CreateEncoder(filename)
        ' if encoder was not found
        If encoder Is Nothing Then
            Throw New System.Exception("Encoder is not found for specified file extension.")
        End If
        ' if encoder is TIFF
        If TypeOf encoder Is Vintasoft.Imaging.Codecs.Encoders.TiffEncoder Then
            ' specify that encoded image must be divided into tiles with size 512x512
            TryCast(encoder, Vintasoft.Imaging.Codecs.Encoders.TiffEncoder).Settings.UseTiles = True
            TryCast(encoder, Vintasoft.Imaging.Codecs.Encoders.TiffEncoder).Settings.TileSize = New System.Drawing.Size(512, 512)
        End If
    
        ' create file
        Using stream As System.IO.Stream = New System.IO.FileStream(filename, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite)
            ' if encoder is multipage
            If TypeOf encoder Is Vintasoft.Imaging.Codecs.Encoders.MultipageEncoderBase Then
                ' save all images
                TryCast(encoder, Vintasoft.Imaging.Codecs.Encoders.MultipageEncoderBase).SaveImages(images, stream)
            Else
                ' check if there is exactly 1 image
                If images.Count <> 1 Then
                    Throw New System.Exception("Single-page encoder cannot be used for saving multiple images.")
                End If
    
                encoder.SaveImage(images(0), stream)
            End If
        End Using
    End Sub
    
    
    
    /// <summary>
    /// Gets an encoder by the filename extension,
    /// changes settings of the encoder and
    /// saves an image collection to a file using encoder.
    /// </summary>
    public static void ChangeEncoderSettingsAndSave(Vintasoft.Imaging.ImageCollection images, string filename)
    {
        // get an encoder by the filename extension
        Vintasoft.Imaging.Codecs.Encoders.EncoderBase encoder =
            Vintasoft.Imaging.Codecs.Encoders.AvailableEncoders.CreateEncoder(filename);
        // if encoder was not found
        if (encoder == null)
        {
            throw new System.Exception("Encoder is not found for specified file extension.");
        }
        // if encoder is TIFF
        if (encoder is Vintasoft.Imaging.Codecs.Encoders.TiffEncoder)
        {
            // specify that encoded image must be divided into tiles with size 512x512
            (encoder as Vintasoft.Imaging.Codecs.Encoders.TiffEncoder).Settings.UseTiles = true;
            (encoder as Vintasoft.Imaging.Codecs.Encoders.TiffEncoder).Settings.TileSize = new System.Drawing.Size(512, 512);
        }
    
        // create file
        using (System.IO.Stream stream = new System.IO.FileStream(filename,
            System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite))
        {
            // if encoder is multipage
            if (encoder is Vintasoft.Imaging.Codecs.Encoders.MultipageEncoderBase)
            {
                // save all images
                (encoder as Vintasoft.Imaging.Codecs.Encoders.MultipageEncoderBase).SaveImages(images, stream);
            }
            else
            {
                // check if there is exactly 1 image
                if (images.Count != 1)
                    throw new System.Exception("Single-page encoder cannot be used for saving multiple images.");
    
                encoder.SaveImage(images[0], stream);
            }
        }
    }
    
    

    Inheritance Hierarchy

    System.Object
       Vintasoft.Imaging.Codecs.Encoders.AvailableEncoders

    Requirements

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

    See Also