VintaSoft Twain .NET SDK 14.1: Руководство для .NET разработчика
Vintasoft.WinTwain Namespace / Device Class / AcquireModal() Method
Синтаксис Exceptions Ремарки Example Требования Смотрите также
В этом разделе
    AcquireModal() Метод (Device)
    В этом разделе
    Получает изображения с устройства синхронно.
    Синтаксис
    'Declaration
    
    Public Function AcquireModal() As AcquireModalState
    
    
    public AcquireModalState AcquireModal()
    
    
    public: AcquireModalState AcquireModal()
    
    
    public:
    AcquireModalState AcquireModal()

    Return Value

    Состояние модального процесса сканирования.
    Исключения
    ИсключениеОписание
    Выбрасывается, если устройство утилизируется.
    Выбрасывается, если устройство находится в неправильном состоянии или устройство не установлено в качестве текущего устройства в менеджере устройств.
    Выбрасывается, если используется .NET отладчик и для оценки функции требуется, чтобы все потоки выполнялись.
    Ремарки

    Важно: Этот метод должен вызываться в цикле, пока он не вернет значение AcquireModalState.None.

    Пример

    Вот C#/VB.NET код, который демонстрирует, как синхронно получать изображения с устройства.

    
    Public Shared Sub AcquireImageModal()
            Try
                    ' create the device manager
                    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.Memory
                            device.PixelType = Vintasoft.Twain.PixelType.BW
    
                            ' create directory for TIFF file
                            Dim directoryForImages As String = System.IO.Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory())
                            directoryForImages = System.IO.Path.Combine(directoryForImages, "Images")
                            If Not System.IO.Directory.Exists(directoryForImages) Then
                                    System.IO.Directory.CreateDirectory(directoryForImages)
                            End If
    
                            Dim multipageTiffFilename As String = System.IO.Path.Combine(directoryForImages, "multipage.tif")
    
                            ' acquire image(s) from the device
                            Dim acquireModalState As Vintasoft.Twain.AcquireModalState = Vintasoft.Twain.AcquireModalState.None
                            Dim imageIndex As Integer = 0
                            Do
                                    acquireModalState = device.AcquireModal()
                                    Select Case acquireModalState
                                            Case Vintasoft.Twain.AcquireModalState.ImageAcquiring
                                                    ' output current state
                                                    System.Console.Write(String.Format("Image is acquiring ", System.Math.Max(System.Threading.Interlocked.Increment(imageIndex),imageIndex - 1)))
                                                    Exit Select
    
                                            Case Vintasoft.Twain.AcquireModalState.ImageAcquiringProgress
                                                    ' output current state
                                                    System.Console.Write(String.Format("{0}% ", device.ImageAcquiringProgressValue))
                                                    Exit Select
    
                                            Case Vintasoft.Twain.AcquireModalState.ImageAcquired
                                                    ' save the acquired image to a file
                                                    device.AcquiredImage.Save(multipageTiffFilename)
                                                    ' dispose the acquired image
                                                    device.AcquiredImage.Dispose()
                                                    ' output current state
                                                    System.Console.WriteLine(String.Format("Image{0} is saved.", System.Math.Max(System.Threading.Interlocked.Increment(imageIndex),imageIndex - 1)))
                                                    Exit Select
    
                                            Case Vintasoft.Twain.AcquireModalState.ScanCompleted
                                                    ' output current state
                                                    System.Console.WriteLine("Scan is completed.")
                                                    Exit Select
    
                                            Case Vintasoft.Twain.AcquireModalState.ScanCanceled
                                                    ' output current state
                                                    System.Console.WriteLine("Scan is canceled.")
                                                    Exit Select
    
                                            Case Vintasoft.Twain.AcquireModalState.ScanFailed
                                                    ' output current state
                                                    System.Console.WriteLine(String.Format("Scan is failed: {0}", device.ErrorString))
                                                    Exit Select
                                    End Select
                            Loop While acquireModalState <> Vintasoft.Twain.AcquireModalState.None
    
                            ' close the device
                            device.Close()
    
                            ' close the device manager
                            deviceManager.Close()
                    End Using
            Catch ex As Vintasoft.Twain.TwainException
                    System.Console.WriteLine("Error: " + ex.Message)
            End Try
    End Sub
    
    
    
    public static void AcquireImageModal()
    {
        try
        {
            // create the device manager
            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.Memory;
                device.PixelType = Vintasoft.Twain.PixelType.BW;
    
                // create directory for TIFF file
                string directoryForImages = System.IO.Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory());
                directoryForImages = System.IO.Path.Combine(directoryForImages, "Images");
                if (!System.IO.Directory.Exists(directoryForImages))
                    System.IO.Directory.CreateDirectory(directoryForImages);
    
                string multipageTiffFilename = System.IO.Path.Combine(directoryForImages, "multipage.tif");
    
                // acquire image(s) from the device
                Vintasoft.Twain.AcquireModalState acquireModalState = Vintasoft.Twain.AcquireModalState.None;
                int imageIndex = 0;
                do
                {
                    acquireModalState = device.AcquireModal();
                    switch (acquireModalState)
                    {
                        case Vintasoft.Twain.AcquireModalState.ImageAcquiring:
                            // output current state
                            System.Console.Write(string.Format("Image is acquiring ", imageIndex++));
                            break;
    
                        case Vintasoft.Twain.AcquireModalState.ImageAcquiringProgress:
                            // output current state
                            System.Console.Write(string.Format("{0}% ", device.ImageAcquiringProgressValue));
                            break;
    
                        case Vintasoft.Twain.AcquireModalState.ImageAcquired:
                            // save the acquired image to a file
                            device.AcquiredImage.Save(multipageTiffFilename);
                            // dispose the acquired image
                            device.AcquiredImage.Dispose();
                            // output current state
                            System.Console.WriteLine(string.Format("Image{0} is saved.", imageIndex++));
                            break;
    
                        case Vintasoft.Twain.AcquireModalState.ScanCompleted:
                            // output current state
                            System.Console.WriteLine("Scan is completed.");
                            break;
    
                        case Vintasoft.Twain.AcquireModalState.ScanCanceled:
                            // output current state
                            System.Console.WriteLine("Scan is canceled.");
                            break;
    
                        case Vintasoft.Twain.AcquireModalState.ScanFailed:
                            // output current state
                            System.Console.WriteLine(string.Format("Scan is failed: {0}", device.ErrorString));
                            break;
                    }
                }
                while (acquireModalState != Vintasoft.Twain.AcquireModalState.None);
    
                // close the device
                device.Close();
    
                // close the device manager
                deviceManager.Close();
            }
        }
        catch (Vintasoft.Twain.TwainException ex)
        {
            System.Console.WriteLine("Error: " + ex.Message);
        }
    }
    
    

    Требования

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

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