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

   Dim Index(1) As Integer

   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, TextEnhancement, Threshold, 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
Dim Scan As New Newtone.ImageKit.Scan
AddHandler Scan.AfterScan, AddressOf Scan_AfterScan

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

'event
Private Sub Scan_AfterScan(ByVal sender As System.Object, ByVal e As Newtone.ImageKit.AfterScanEventArgs)
  If Not (e.Bitmap1 Is Nothing) Then
    e.Bitmap1.Save(e.ImageNumber.ToString("d02") + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp)
  End If
End Sub



[Visual C#.NET]
bool Ret;
Newtone.ImageKit.Scan scan = new Newtone.ImageKit.Scan();
scan.AfterScan += new Newtone.ImageKit.AfterScanEventHandler(scan_AfterScan);

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

//event
private void scan_AfterScan(object sender, Newtone.ImageKit.AfterScanEventArgs e)
{
  if (e.Bitmap1 != null)
    e.Bitmap1.Save(e.ImageNumber.ToString("d02") + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
}

See Also

Scan Class | Scan Members


The ImageKit.NET3 is created by Newtone Corporation