VintaSoft Twain .NET SDK 15.4: Documentation for .NET developer
Vintasoft.WpfTwain Namespace / Device Class / ImageCompression Property
Syntax Exceptions Remarks Example Requirements SeeAlso
In This Topic
ImageCompression Property (Device)
In This Topic
Gets or sets the image compression for images when Memory or File transfer mode is used.
Syntax
'Declaration

Public Property ImageCompression As TwainImageCompression

public TwainImageCompression ImageCompression { get; set; }

Exceptions
ExceptionDescription
Thrown if device is in wrong state.
Thrown if device does not support capability.
Thrown if the .NET debugger is used and the function evaluation requires all threads to run.
Remarks

Call this property only when device is opened (State == DeviceState.Opened).

Supported image compressions can be received by the GetSupportedImageCompressions method.

Example

This C#/VB.NET code shows how to save acquire images directly to a disk as TIFF files with CCITT Group 4 compression.


Public Sub AcquireImagesUsingFileTransferModeAsTiffFiles()
    Using deviceManager As New Vintasoft.Twain.DeviceManager()
        ' open the device manager
        deviceManager.Open()

        ' get reference to the default device
        Dim device As Vintasoft.Twain.Device = deviceManager.DefaultDevice

        device.ShowUI = False
        device.DisableAfterAcquire = True

        ' open the device
        device.Open()

        ' set acquisition parameters
        device.TransferMode = Vintasoft.Twain.TransferMode.File
        device.FileFormat = Vintasoft.Twain.TwainImageFileFormat.Tiff
        device.ImageCompression = Vintasoft.Twain.TwainImageCompression.Group4

        Dim imageCount As Integer = 0
        ' set filename the first acquired image
        device.FileName = String.Format("c:\images\page{0}.tif", System.Math.Max(System.Threading.Interlocked.Increment(imageCount), imageCount - 1))

        ' acquire images from device
        Dim acquireModalState As Vintasoft.Twain.AcquireModalState = Vintasoft.Twain.AcquireModalState.None
        Do
            acquireModalState = device.AcquireModal()
            Select Case acquireModalState
                Case Vintasoft.Twain.AcquireModalState.ImageAcquired
                    ' set filename for next acquired image
                    device.FileName = String.Format("c:\images\page{0}.tif", System.Math.Max(System.Threading.Interlocked.Increment(imageCount), imageCount - 1))
                    Exit Select
            End Select
        Loop While acquireModalState <> Vintasoft.Twain.AcquireModalState.None

        ' close the device
        device.Close()

        ' close the device manager
        deviceManager.Close()
    End Using
End Sub


public void AcquireImagesUsingFileTransferModeAsTiffFiles()
{
    using (Vintasoft.Twain.DeviceManager deviceManager = new Vintasoft.Twain.DeviceManager())
    {
        // open the device manager
        deviceManager.Open();

        // get reference to the default device
        Vintasoft.Twain.Device device = deviceManager.DefaultDevice;

        device.ShowUI = false;
        device.DisableAfterAcquire = true;

        // open the device
        device.Open();

        // set acquisition parameters
        device.TransferMode = Vintasoft.Twain.TransferMode.File;
        device.FileFormat = Vintasoft.Twain.TwainImageFileFormat.Tiff;
        device.ImageCompression = Vintasoft.Twain.TwainImageCompression.Group4;

        int imageCount = 0;
        // set filename the first acquired image
        device.FileName = string.Format(@"c:\images\page{0}.tif", imageCount++);

        // acquire images from device
        Vintasoft.Twain.AcquireModalState acquireModalState = Vintasoft.Twain.AcquireModalState.None;
        do
        {
            acquireModalState = device.AcquireModal();
            switch (acquireModalState)
            {
                case Vintasoft.Twain.AcquireModalState.ImageAcquired:
                    // set filename for next acquired image
                    device.FileName = string.Format(@"c:\images\page{0}.tif", imageCount++);
                    break;
            }
        }
        while (acquireModalState != Vintasoft.Twain.AcquireModalState.None);

        // close the device
        device.Close();

        // close the device manager
        deviceManager.Close();
    }
}

Requirements

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

See Also