VintaSoft Twain .NET SDK 15.4: Documentation for .NET developer
In This Topic
How to get value of TWAIN device capability?
In This Topic
Here is an example that demonstrates how to use properties and methods of TWAIN capability for getting information about pixel types supported by TWAIN device:
/// <summary>
/// Get information about pixel types supported by device.
/// </summary>
public void GetPixelTypesInfo(Vintasoft.Twain.Device device)
{
    // open the device
    device.Open();

    // get reference to the object that manipulates IPixelType capability
    Vintasoft.Twain.DeviceCapability pixelTypeCap = device.Capabilities.Find(Vintasoft.Twain.DeviceCapabilityId.IPixelType);
    // if the IPixelType capability is supported
    if (pixelTypeCap != null)
    {
        // get information about current, default and supported values of capability

        Vintasoft.Twain.TwainValueContainerBase capValue = pixelTypeCap.GetValue();

        switch (capValue.ContainerType)
        {
            case Vintasoft.Twain.TwainValueContainerType.Enum:
                Vintasoft.Twain.TwainEnumValueContainer capValueAsEnum = (Vintasoft.Twain.TwainEnumValueContainer)capValue;
                System.Array enumValues = capValueAsEnum.EnumValues;

                // output the capability values in human readable format
                System.Console.WriteLine(string.Format("Current pixel type: {0}", enumValues.GetValue(capValueAsEnum.ValueIndex)));
                System.Console.WriteLine(string.Format("Default pixel type: {0}", enumValues.GetValue(capValueAsEnum.DefaultValueIndex)));
                System.Console.Write("Supported pixel types:");
                for (int i = 0; i < enumValues.Length; i++)
                    System.Console.Write(string.Format(" {0}", enumValues.GetValue(i)));
                break;
        }

        System.Console.WriteLine();
    }

    // close the device
    device.Close();
}
''' <summary>
''' Get information about pixel types supported by device.
''' </summary>
Public Sub GetPixelTypesInfo(device As Vintasoft.Twain.Device)
    ' open the device
    device.Open()

    ' get reference to the object that manipulates IPixelType capability
    Dim pixelTypeCap As Vintasoft.Twain.DeviceCapability = device.Capabilities.Find(Vintasoft.Twain.DeviceCapabilityId.IPixelType)
    ' if the IPixelType capability is supported
    If pixelTypeCap IsNot Nothing Then
        ' get information about current, default and supported values of capability

        Dim capValue As Vintasoft.Twain.TwainValueContainerBase = pixelTypeCap.GetValue()

        Select Case capValue.ContainerType
            Case Vintasoft.Twain.TwainValueContainerType.[Enum]
                Dim capValueAsEnum As Vintasoft.Twain.TwainEnumValueContainer = DirectCast(capValue, Vintasoft.Twain.TwainEnumValueContainer)
                Dim enumValues As System.Array = capValueAsEnum.EnumValues

                ' output the capability values in human readable format
                System.Console.WriteLine(String.Format("Current pixel type: {0}", enumValues.GetValue(capValueAsEnum.ValueIndex)))
                System.Console.WriteLine(String.Format("Default pixel type: {0}", enumValues.GetValue(capValueAsEnum.DefaultValueIndex)))
                System.Console.Write("Supported pixel types:")
                For i As Integer = 0 To enumValues.Length - 1
                    System.Console.Write(String.Format(" {0}", enumValues.GetValue(i)))
                Next
                Exit Select
        End Select

        System.Console.WriteLine()
    End If

    ' close the device
    device.Close()
End Sub