VintaSoft Twain .NET SDK v10.2
ImageCompression Property (Device)
Example 




Vintasoft.Twain Namespace > Device Class : ImageCompression Property
Gets or sets the image compression for images when Memory or File transfer mode is used.
Syntax
'Declaration
 
Public Property ImageCompression As TwainImageCompression
'Usage
 
Dim instance As Device
Dim value As TwainImageCompression
 
instance.ImageCompression = value
 
value = instance.ImageCompression
public TwainImageCompression ImageCompression {get; set;}
public: __property TwainImageCompression get_ImageCompression();
public: __property void set_ImageCompression( 
   TwainImageCompression value
);
public:
property TwainImageCompression ImageCompression {
   TwainImageCompression get();
   void set (    TwainImageCompression value);
}
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 example 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 DeviceManager()
        ' open the device manager
        deviceManager.Open()
            
        ' get reference to the default device
        Dim device As Device = deviceManager.DefaultDevice
            
        device.ShowUI = False
        device.DisableAfterAcquire = True
            
        ' open the device
        device.Open()
            
        ' set acquisition parameters
        device.TransferMode = TransferMode.File
        device.FileFormat = TwainImageFileFormat.Tiff
        device.ImageCompression = 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 acquireModalState1 As AcquireModalState = AcquireModalState.None
        Do
            acquireModalState1 = device.AcquireModal()
            Select Case acquireModalState1
                Case 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 acquireModalState1 <> AcquireModalState.None
            
        ' close the device
        device.Close()
            
        ' close the device manager
        deviceManager.Close()
    End Using
End Sub
public void AcquireImagesUsingFileTransferModeAsTiffFiles()
{
    using (DeviceManager deviceManager = new DeviceManager())
    {
        // open the device manager
        deviceManager.Open();
            
        // get reference to the default device
        Device device = deviceManager.DefaultDevice;
            
        device.ShowUI = false;
        device.DisableAfterAcquire = true;
            
        // open the device
        device.Open();
            
        // set acquisition parameters
        device.TransferMode = TransferMode.File;
        device.FileFormat = TwainImageFileFormat.Tiff;
        device.ImageCompression = 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
        AcquireModalState acquireModalState = AcquireModalState.None;
        do
        {
            acquireModalState = device.AcquireModal();
            switch (acquireModalState)
            {
                case AcquireModalState.ImageAcquired:
                    // set filename for next acquired image
                    device.FileName = string.Format(@"c:\images\page{0}.tif", imageCount++);
                    break;
            }
        }
        while (acquireModalState != AcquireModalState.None);
            
        // close the device
        device.Close();
            
        // close the device manager
        deviceManager.Close();
    }
}
Requirements

Target Platforms: Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

See Also

Reference

Device Class
Device Members
GetSupportedImageCompressions Method
Open Method
TransferMode Property