This method retrieves an image from a TWAIN datasource (scan device).

[Visual Basic] Public Function Execute() As Boolean
Public Function Execute(ByVal index() As Integer) As Boolean
[C#] public bool Execute();
public bool Execute(int[] index);

Parameters

index
     An array containing the image indexes. (used with a digial camera)

Return Value

Returns true if successful. Returns False if unsuccessful.

Explanation

The Execute method retrieves an image from a TWAIN datasource (scan device). Events (BeforeScan, AfterScan, Scanning) are generated before, during, and after the scan so it is possible to write processing code in each of these stages of the scan process.

The Index parameter is enabled only when the UserInterface property is Suppress and the Mode property is set for a digital camera. However, in other situations where this array of index values is not needed, please use methods which doesn't have any parameters. The Index parameter is used to specify which image is retrieved from the digital camera (the index parameter is enabled when the Mode property is CameraArray or CameraThumbnailArray).

For example, to retrieve the 5th and 8th image from a digital camera, set the Index array parameter to

   Index(0) = 5

   Index(1) = 8

Some scan devices do not support these functions. In such cases, only the supported functions are used to scan the image.

Prior to executing the Execute method, you must execute the Initialize method.

If the OpenDataSource method is executed prior to the Execute method, then while the scan device is open, other applications can not use that scan device and it becomes the exclusive datasource for this execution.

The following properties should be set prior to executing the Execute method

[Required properties]

[These properties may be required depending on the settings]

[If the UserInterface property is Suppress and the Mode property is InformationFile]

[If the UserInterface property is Suppress and the Mode property is NOT InformationFile]

  1. When using a scanner, it is recommended that the following properties be set:
    AdjustGamma, AutoBright, BitDepth, BitDepthReduction, Border, BorderColor, BorderDetection, Brightness, ColorBWRatio, Contrast, Deskew , DropoutColor, DynamicThreshold, FocusPosition, Gamma, HalfTone, Highlight, IgnoreBackColor, ImageFilter, ImageMerge, Mode, MoireFilter, NoiseFilter, Orientation, OverScan, PageCount, PaperSize, PixelType, RemoveHole, RotateBack, Rotation, ScanningSpeed, Shadow, Sharpness, SkipBlankPage, SkipBlankThreshold, Threshold, TextEnhancement, Unit, XResolution, XScaling, YResolution, YScaling, PaperSize<=0: Rect

    Note: The AdjustGamma, Border, BorderColor, ColorBWRatio, DynamicThreshold, FocusPosition, IgnoreBackColor, MoireFilter , RemoveHole, RotateBack, ScanningSpeed , Sharpness, SkipBlankThreshold, TextEnhancement properties are sometimes disabled depending on the scan driver.
  2. When using a digital camera, it is recommended that these properties be set:
    Mode, PageCount (when the Index parameter is unnecessary), Unit

<The following properties are set after the scan has executed>

BitDepth, Compression, ErrorStatus, FileFormat (when using file transfer method), PixelType , Rect, Count, Unit, XResolution, YResolution

For details, please refer to the respective properties' explanations.

 

Important points when using a custom built user interface (UserInterface = Suppress)

When UserInterface is Suppress, depending on the scan device and the property values set, the scan can fail. For the most part the causes for scan failure when the UserInterface is Suppress can be traced to the following:

  1. The scan units set are not supported by the scan device. The supported scan unit values can be retrieved using the GetCapabilityEnumToSingle method.
  2. The pixel type set is not supported by the scan device. The supported pixel type values can be retrieved using the GetCapabilityEnumToSingle method.
  3. The bit count set is not supported by the scan device. The supported bit count values can be retrieved using the GetBitDepth method.
  4. The resolution set is not supported by the scan device. The supported resolution values can be retrieved using the GetCapabilityEnumToSingle or the GetCapabilityRange methods.
  5. The paper size set is not supported by the scan device. The supported values can be retrieved using the GetCapabilityEnumToSingle method.
    1. If settings for paper size are not supported at all, then set the PaperSize property to UserSize and set the appropriate scan area in the Rect property. If the scan area is not correctly set (i.e. it is smaller than the minimum or larger than the maximum), the scan can fail. The proper scan area values can be retrieved using the GetMinimumSize and GetPhysicalSize methods.
    2. If paper size settings are supported and the scan still fails, check to make sure the PaperSize property is set to a value other than UserSize.

Example

Scan using the scan driver's user interface

[Visual Basic.NET]
Dim Ret As Boolean
Ret = ImageKit1.Scan.Initialize(Me.Handle, 1, 0, "1.00", "NEWTONE Corp.", "ImageKit", "ImageKit.NET Scan Sample")
If Ret = false Then Exit Sub
ImageKit1.Scan.ClearProperty()
ImageKit1.Scan.Transfer = ScanTransfer.Memory
ImageKit1.Scan.Compression = ScanCompression.None
ImageKit1.Scan.UserInterface = ScanUserInterface.Show
ImageKit1.Scan.DataSourceName = "EPSON TWAIN Pro"
Ret = ImageKit1.Scan.Execute()
Ret = ImageKit1.Scan.Terminate()

'event
Private Sub ImageKit1_AfterScan(ByVal sender As Object, ByVal e As Newtone.ImageKit.AfterScanEventArgs) Handles ImageKit1.AfterScan
  If (e.Bitmap1 Is Nothing) Then Exit Sub

  ImageKit1.Image = e.Bitmap1.Clone()
  ImageKit1.Display(Newtone.ImageKit.Win.DisplayMode.Stretch)
End Sub

[Visual C#.NET]
bool Ret;
Ret = imageKit1.Scan.Initialize(this.Handle, 1, 0, "1.00", "NEWTONE Corp.", "ImageKit", "ImageKit.NET Scan Sample");
if (!Ret) return;
imageKit1.Scan.ClearProperty();
imageKit1.Scan.Transfer = ScanTransfer.Memory;
imageKit1.Scan.Compression = ScanCompression.None;
imageKit1.Scan.UserInterface = ScanUserInterface.Show;
imageKit1.Scan.DataSourceName = "EPSON TWAIN Pro";
Ret = imageKit1.Scan.Execute();
Ret = imageKit1.Scan.Terminate();

//event
private void imageKit1_AfterScan(object sender, Newtone.ImageKit.AfterScanEventArgs e)
{
  if (e.Bitmap1 == null) return;

  imageKit1.Image = (Image)e.Bitmap1.Clone();
  imageKit1.Display(Newtone.ImageKit.Win.DisplayMode.Stretch);
}

See Also

Scan Members | Newtone.ImageKit.Win.ImageKit

The ImageKit.NET3 is created by Newtone Corporation