←Select platform

Acquire Method

Summary
Acquires one or more images from a WIA source.

Syntax
C#
C++/CLI
Python
public DialogResult Acquire( 
   IntPtr owner, 
   object item, 
   WiaAcquireFlags flags 
) 
public: 
DialogResult Acquire(  
   IntPtr owner, 
   Object^ item, 
   WiaAcquireFlags flags 
)  
def Acquire(self,flags): 

Parameters

owner
Window handle of your application window.

item
This parameter is only used when acquiring from scanner device and the ShowUserInterface flag is NOT set. Use this parameter to specify the scanner's paper source (Feeder or Flatbed).

This flag is optional. If you are using WIA 1.0 you can change the paper source by changing the WiaPropertyId.ScannerDeviceDocumentHandlingSelect property value for the root item or by enumerating the available scanner items and passing the item to be used for scanning.

If you are using WIA 2.0 either enumerate the available scanner items and pass the item to be used for scanning, or pass null (Nothing in VB), in which case the enumeration will be performed internally and the first enumerated item will be used as the source item.

flags
Flag that determines certain actions of the WIA image acquisition selection dialog box. Possible values are:

Value

Meaning

WiaAcquireFlags.None Default behavior for the device image acquisition dialog box.
WiaAcquireFlags.SingleImage Restrict image selection to a single image in the device image acquisition dialog box. This flag is not available if you are using WIA version 2.0.
WiaAcquireFlags.ShowUserInterface Show the manufacturer's image acquisition dialog box.
WiaAcquireFlags.UseCommonUI Use the system user interface (UI), if available, rather than the vendor-supplied UI. If the system UI is not available, the vendor UI is used.

Return Value

One of the DialogResult values. If an error occurs, an exception is thrown.

Remarks

This function will acquire single or multiple images from the selected WIA device.

Make sure to call WiaSession.Startup and then call any of the WiaSession.SelectDeviceDlg or WiaSession.SelectDevice functions before calling this function.

You can change the AcquireOptions property members before calling this method to control some options while acquiring from the WIA source.

Set this method for memory transfer or file transfer by performing one of the following:

When performing memory transfer you need to add the AcquireEvent event to receive the acquired page(s). The event will also provide you with the percent completion of the page transfer progress.

When performing file transfer it is optional to add the AcquireEvent event since the event will only provide you with the saved file path and the percent completion of the file saving process.

When performing file transfer two properties within the WiaSession class will become available:

  • FilesCount - contains the count of the saved files.
  • FilesPaths - a collection that contains the saved file paths and filenames.

To cancel the acquire operation you need to add the AcquireEvent event and set the Cancel member of the WiaAcquireEventArgs to true.

Value

Meaning

WiaAcquireFlags.None Default behavior for the device image acquisition dialog box.
WiaAcquireFlags.SingleImage Restrict image selection to a single image in the device image acquisition dialog box. This flag is not available if you are using WIA version 2.0.
WiaAcquireFlags.ShowUserInterface Show the manufacturer's image acquisition dialog box.
WiaAcquireFlags.UseCommonUI Use the system user interface (UI), if available, rather than the vendor-supplied UI. If the system UI is not available, the vendor UI is used.

Note:

If the ShowUserInterface flag is set for any of the acquire methods, then be aware that some of the previously set/changed user properties (using any of the SetPropertyXxx or SetProperties methods) will be overwritten by the Microsoft's image acquisition dialog box. Microsoft's image acquisition dialog box sets its own initialization properties like the current intent (image type), selected area (left, top, width and height), paper source and duplex mode, ...etc.

In order to suppress the manufacturer's image acquisition dialog and acquire directly from the specified source item through the item parameter using the values set through the SetPropertyXxx and SetProperties methods, do not set the ShowUserInterface flag.

Note: While running a Win32 version application that calls this function on Windows VISTA 64-Bit we have noticed that the FilesCount and FilesPaths properties will not be updated with the required information. This is a known limitation of Microsoft's WIA toolkit.
Note: If you are using WIA 2.0 and the ShowUserInterface flag is set it is not necessary to add the AcquireEvent event. Microsoft's WIA 2.0 acquire dialog does not provide an event but performs all the processing and returns with a count of the number of files saved and their paths through the FilesCount and FilesPaths properties.

For more information, refer to How to Acquire from the WIA Source.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Wia; 
 
 
      
public void IsAvailableExample(IntPtr parent) 
{ 
   if (!WiaSession.IsAvailable(WiaVersion.Version1)) 
   { 
      Console.WriteLine("WIA version 1.0 not installed."); 
      return; 
   } 
 
   WiaSession wiaSession = new WiaSession(); 
   wiaSession.Startup(WiaVersion.Version1); 
 
   DialogResult res = wiaSession.SelectDeviceDlg(parent, WiaDeviceType.Default, WiaSelectSourceFlags.NoDefault); 
   if (res != DialogResult.OK) 
   { 
      Console.WriteLine("Error selecting WIA device."); 
      wiaSession.Shutdown(); 
      return; 
   } 
 
   // Initialize and fill the required fields from the WiaAcquireOptions structure 
   WiaAcquireOptions wiaAcquireOptions = WiaAcquireOptions.Empty; 
   wiaAcquireOptions.MemoryBufferSize = 32 * 1024; 
   wiaAcquireOptions.DoubleBuffer = true; 
   wiaSession.AcquireOptions = wiaAcquireOptions; 
 
   wiaSession.AcquireEvent += new EventHandler<WiaAcquireEventArgs>(wiaSession_AcquireEvent); 
 
   wiaSession.Acquire(parent, null, WiaAcquireFlags.ShowUserInterface | WiaAcquireFlags.UseCommonUI); 
 
   wiaSession.AcquireEvent -= new EventHandler<WiaAcquireEventArgs>(wiaSession_AcquireEvent); 
   wiaSession.Shutdown(); 
} 
 
public void wiaSession_AcquireEvent(object sender, WiaAcquireEventArgs e) 
{ 
   Application.DoEvents(); 
 
   if ((e.Flags & WiaAcquiredPageFlags.StartOfPage) == WiaAcquiredPageFlags.StartOfPage) 
      Console.WriteLine("Beginning of data transfer."); 
   else if ((e.Flags & WiaAcquiredPageFlags.EndOfPage) == WiaAcquiredPageFlags.EndOfPage) 
      Console.WriteLine("End of data transfer."); 
 
   if (e.Image != null) 
   { 
      // You can load the image here. 
   } 
 
   e.Cancel = false; 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Wia Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.