VintaSoft Imaging .NET SDK 14.1: Документация для .NET разработчика
Vintasoft.Imaging.Codecs.Encoders Namespace / AvailableEncoders Class
Члены типа Объект Синтаксис Example Иерархия Требования Смотрите также
    Класс AvailableEncoders
    Содержит статические свойства и методы, которые позволяют получить список доступных кодировщиков и найти кодировщик изображения, используя расширение имени файла.
    Объектная модель
    AvailableEncoders
    Синтаксис
    'Declaration
    
    Public MustInherit NotInheritable Class AvailableEncoders
    
    
     
    Пример

    Вот пример, показывающий, как получить кодировщик для указанного имени файла, изменить настройки энкодера и сохранить указанные изображения в файл с помощью кодировщика:

    ''' <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);
            }
        }
    }
    
    

    Иерархия наследования

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

    Требования

    Целевые платформы: .NET 9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    Смотрите также