VintaSoft Twain .NET SDK v10.2
Vintasoft.WpfTwain Namespace / AcquiredImage Class
Members Example




In This Topic
    AcquiredImage Class
    In This Topic
    Class that represents an image acquired from TWAIN device.
    Object Model
    AcquiredImage ClassImageInfo Class
    Syntax
    'Declaration
     
    Public NotInheritable Class AcquiredImage 
    'Usage
     
    Dim instance As AcquiredImage
    public sealed class AcquiredImage 
    public __gc __sealed class AcquiredImage 
    public ref class AcquiredImage sealed 
    Example
    This example shows how to acquire images from the device, process images and save to a multipage TIFF file only not blank images.
    Public Shared Sub AcquireAndProcessImages()
        ' create the device manager
        Using deviceManager As New DeviceManager()
            ' open the device manager
            deviceManager.Open()
                
            ' select the device in the default device selectio ndialog
            deviceManager.ShowDefaultDeviceSelectionDialog()
                
            ' get reference to the selected device
            Dim device As Device = deviceManager.DefaultDevice
                
            ' specify that device UI must not be used
            device.ShowUI = False
            ' specify that device must be closed after scan
            device.DisableAfterAcquire = True
                
            Dim tiffFilename As String = Path.Combine(Directory.GetCurrentDirectory(), "multipage.tif")
                
            ' acquire images from device
            Dim acquireModalState1 As AcquireModalState = AcquireModalState.None
            Dim acquiredImage As AcquiredImage
            Do
                acquireModalState1 = device.AcquireModal()
                Select Case acquireModalState1
                    Case AcquireModalState.ImageAcquired
                        ' get reference to the image acquired from device
                        acquiredImage = device.AcquiredImage
                
                        ' despeckle/deskew/detect border
                        ProcessAcquiredImage(acquiredImage)
                        ' add image to multipage TIFF file if image is not blank
                        If Not acquiredImage.IsBlank(0.01F) Then
                            acquiredImage.Save(tiffFilename)
                        End If
                
                        ' dispose acquired image
                        acquiredImage.Dispose()
                        Exit Select
                End Select
            Loop While acquireModalState1 <> AcquireModalState.None
                
            ' close the device
            device.Close()
                
            ' close the device manager
            deviceManager.Close()
        End Using
    End Sub
                
    Private Shared Sub ProcessAcquiredImage(ByVal acquiredImage As AcquiredImage)
        Console.WriteLine(String.Format("Image ({0})", acquiredImage.ImageInfo))
                
        Try
            ' subscribe to processing events
            AddHandler acquiredImage.Processing, New EventHandler(Of AcquiredImageProcessingEventArgs)(AddressOf acquiredImage_Processing)
            AddHandler acquiredImage.Progress, New EventHandler(Of AcquiredImageProcessingProgressEventArgs)(AddressOf acquiredImage_Progress)
            AddHandler acquiredImage.Processed, New EventHandler(Of AcquiredImageProcessedEventArgs)(AddressOf acquiredImage_Processed)
                
            ' despeckle/deskew/detect border
            acquiredImage.Despeckle(8, 25, 30, 400)
            acquiredImage.Deskew(BorderColor.AutoDetect, 5, 5)
            acquiredImage.DetectBorder(5)
        Catch ex As ImagingException
            Console.WriteLine("Error: " + ex.Message)
        Finally
            ' unsubscribe from processing events
            RemoveHandler acquiredImage.Processing, New EventHandler(Of AcquiredImageProcessingEventArgs)(AddressOf acquiredImage_Processing)
            RemoveHandler acquiredImage.Progress, New EventHandler(Of AcquiredImageProcessingProgressEventArgs)(AddressOf acquiredImage_Progress)
            RemoveHandler acquiredImage.Processed, New EventHandler(Of AcquiredImageProcessedEventArgs)(AddressOf acquiredImage_Processed)
        End Try
    End Sub
                
    Private Shared Sub acquiredImage_Processing(ByVal sender As Object, ByVal e As AcquiredImageProcessingEventArgs)
        Console.Write(e.Action.ToString() + " ")
    End Sub
                
    Private Shared Sub acquiredImage_Progress(ByVal sender As Object, ByVal e As AcquiredImageProcessingProgressEventArgs)
        Console.Write(".")
    End Sub
                
    Private Shared Sub acquiredImage_Processed(ByVal sender As Object, ByVal e As AcquiredImageProcessedEventArgs)
        Console.WriteLine(" finished")
    End Sub
    public static void AcquireAndProcessImages()
    {
        // create the device manager
        using (DeviceManager deviceManager = new DeviceManager())
        {
            // open the device manager
            deviceManager.Open();
                
            // select the device in the default device selectio ndialog
            deviceManager.ShowDefaultDeviceSelectionDialog();
                
            // get reference to the selected device
            Device device = deviceManager.DefaultDevice;
                
            // specify that device UI must not be used
            device.ShowUI = false;
            // specify that device must be closed after scan
            device.DisableAfterAcquire = true;
                
            string tiffFilename = Path.Combine(Directory.GetCurrentDirectory(), "multipage.tif");
                
            // acquire images from device
            AcquireModalState acquireModalState = AcquireModalState.None;
            AcquiredImage acquiredImage;
            do
            {
                acquireModalState = device.AcquireModal();
                switch (acquireModalState)
                {
                    case AcquireModalState.ImageAcquired:
                        // get reference to the image acquired from device
                        acquiredImage = device.AcquiredImage;
                
                        // despeckle/deskew/detect border
                        ProcessAcquiredImage(acquiredImage);
                        // add image to multipage TIFF file if image is not blank
                        if (!acquiredImage.IsBlank(0.01f))
                            acquiredImage.Save(tiffFilename);
                
                        // dispose acquired image
                        acquiredImage.Dispose();
                        break;
                }
            }
            while (acquireModalState != AcquireModalState.None);
                
            // close the device
            device.Close();
        
            // close the device manager
            deviceManager.Close();
        }
    }
                
    private static void ProcessAcquiredImage(AcquiredImage acquiredImage)
    {
        Console.WriteLine(string.Format("Image ({0})", acquiredImage.ImageInfo));
                
        try
        {
            // subscribe to processing events
            acquiredImage.Processing += new EventHandler<AcquiredImageProcessingEventArgs>(acquiredImage_Processing);
            acquiredImage.Progress += new EventHandler<AcquiredImageProcessingProgressEventArgs>(acquiredImage_Progress);
            acquiredImage.Processed += new EventHandler<AcquiredImageProcessedEventArgs>(acquiredImage_Processed);
                
            // despeckle/deskew/detect border
            acquiredImage.Despeckle(8, 25, 30, 400);
            acquiredImage.Deskew(BorderColor.AutoDetect, 5, 5);
            acquiredImage.DetectBorder(5);
        }
        catch (ImagingException ex)
        {
            Console.WriteLine("Error: " + ex.Message);
        }
        finally
        {
            // unsubscribe from processing events
            acquiredImage.Processing -= new EventHandler<AcquiredImageProcessingEventArgs>(acquiredImage_Processing);
            acquiredImage.Progress -= new EventHandler<AcquiredImageProcessingProgressEventArgs>(acquiredImage_Progress);
            acquiredImage.Processed -= new EventHandler<AcquiredImageProcessedEventArgs>(acquiredImage_Processed);
        }
    }
                
    static void acquiredImage_Processing(object sender, AcquiredImageProcessingEventArgs e)
    {
        Console.Write(e.Action.ToString() + " ");
    }
                
    static void acquiredImage_Progress(object sender, AcquiredImageProcessingProgressEventArgs e)
    {
        Console.Write(".");
    }
                
    static void acquiredImage_Processed(object sender, AcquiredImageProcessedEventArgs e)
    {
        Console.WriteLine(" finished");
    }
    Inheritance Hierarchy

    System.Object
       Vintasoft.WpfTwain.AcquiredImage

    Requirements

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

    See Also