Как отсканировать верхнюю сторону страницы с помощью TWAIN сканера?
В этом разделе
Класс Vintasoft.Twain.DeviceImageLayout позволяет управлять макетом изображения на TWAIN устройстве.
Вот C#/VB.NET код, который демонстрирует, как отсканировать только верхнюю сторону страницы с помощью TWAIN Сканера:
private void AcquirePartOfImage()
{
using (Vintasoft.Twain.DeviceManager deviceManager = new Vintasoft.Twain.DeviceManager())
{
try
{
// open the device manager
deviceManager.Open();
deviceManager.ShowDefaultDeviceSelectionDialog();
// get reference to the default device
Vintasoft.Twain.Device device = deviceManager.DefaultDevice;
device.ShowUI = false;
device.DisableAfterAcquire = true;
// open the device
device.Open();
// set image layout (get only the top half of the page)
device.UnitOfMeasure = Vintasoft.Twain.UnitOfMeasure.Inches;
Vintasoft.Primitives.VintasoftRectF imageLayout = device.ImageLayout.Get();
device.ImageLayout.Set(0, 0, imageLayout.Width, imageLayout.Height / 2);
string tiffFilename = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "multipage.tif");
// acquire images from device
Vintasoft.Twain.AcquireModalState acquireModalState = Vintasoft.Twain.AcquireModalState.None;
do
{
acquireModalState = device.AcquireModal();
switch (acquireModalState)
{
case Vintasoft.Twain.AcquireModalState.ImageAcquired:
// save acquired image to multipage TIFF file
device.AcquiredImage.Save(tiffFilename);
// dispose the acquired image
device.AcquiredImage.Dispose();
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);
System.Console.ReadLine();
}
}
}
Private Sub AcquirePartOfImage()
Using deviceManager As New Vintasoft.Twain.DeviceManager()
Try
' open the device manager
deviceManager.Open()
deviceManager.ShowDefaultDeviceSelectionDialog()
' 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 image layout (get only the top half of the page)
device.UnitOfMeasure = Vintasoft.Twain.UnitOfMeasure.Inches
Dim imageLayout As Vintasoft.Primitives.VintasoftRectF = device.ImageLayout.[Get]()
device.ImageLayout.[Set](0, 0, imageLayout.Width, imageLayout.Height / 2)
Dim tiffFilename As String = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "multipage.tif")
' 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
' save acquired image to multipage TIFF file
device.AcquiredImage.Save(tiffFilename)
' dispose the acquired image
device.AcquiredImage.Dispose()
Exit Select
End Select
Loop While acquireModalState <> Vintasoft.Twain.AcquireModalState.None
' close the device
device.Close()
' close the device manager
deviceManager.Close()
Catch ex As Vintasoft.Twain.TwainException
System.Console.WriteLine("Error: " + ex.Message)
System.Console.ReadLine()
End Try
End Using
End Sub