Web Demos

BARCODE READER SDK DEMO

Explore the flexibe barcode reading settings to optimize for your specific usage scenario.

WEB TWAIN SDK DEMO

Try the most popular web scanner features: scan images, import local images and PDF files, edit, save to local, upload to database, and etc.

BARCODE READER JAVASCRIPT DEMO

Transform any camera-equipped devices into real-time, browser-based barcode and QR code scanners.

MRZ SCANNER WEB DEMO

Detects the machine-readable zone of a passport, scans the text, and parses into human-readable data.

APP STORE DEMOS

BARCODE READER SDK FOR IOS

BARCODE READER SDK FOR ANDROID

VIEW MORE DEMOS >
Dev Center
Table of contents

{WebTwainObject} Edit

The properties and methods on this page live in the namespace {WebTwainObject}. {WebTwainObject} denotes the WebTwain instance. Learn about how to create a web twain object.

Methods

       
Crop() CropToClipboard() CutFrameToClipboard() CutToClipboard()
CopyToClipboard() Erase() Flip() Mirror()
Rotate() RotateEx() RotateLeft() RotateRight()
ChangeBitDepth() SetDPI() ConvertToBW() ConvertToGrayScale()
ChangeImageSize() Invert() SetImageWidth() ChangeBrightnessAsync()
ChangeContrastAsnyc()      

Properties

 
BackgroundFillColor

ChangeBitDepth

Change the bit depth of the specified image.

Syntax

ChangeBitDepth(
    index: number,
    bitDepth: number,
    highQuality: boolean,
): boolean;

Parameters

index: Specify the index of the image to be changed. The index is 0-based.

bitDepth: Specify the target bit depth.

highQuality: Whether to keep high quality. When it’s true, it takes more time.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v10.0+ v10.0+ v11.0+ v11.0+ not supported not supported

Usage notes

The allowed bit depths are 1, 4, 8, 24.


ChangeImageSize

Change the size of the specified image.

Syntax

ChangeImageSize(
    index: number,
    width: number,
    height: number,
    method: Dynamsoft.DWT.EnumDWT_InterpolationMethod | number,
    successCallback?: () => void,
    failureCallback?: (
        errorCode: number,
        errorString: string
    ) => void
): void | boolean;

Parameters index: Specify the index of the image to be changed. The index is 0-based.

width: Specify the new width.

height: Specify the new height.

method: Specify the algorithm for the change. Please refer to EnumDWT_InterpolationMethod.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v4.0+ v10.0+ v11.0+ v11.0+ v12.1+ v16.0+

SetDPI

Change the DPI (dots per inch) of the specified image.

Syntax

SetDPI(
    index: number,
    xResolution: number,
    yResolution: number,
    resample: boolean,
    method: Dynamsoft.DWT.EnumDWT_InterpolationMethod | number,
    successCallback?: () => void,
    failureCallback?: (
        errorCode: number,
        errorString: string
    ) => void
): void | boolean;

Parameters

index: Specify the index of the image to be changed. The index is 0-based.

xResolution: Specify the horizontal DPI.

yResolution: Specify the vertical DPI.

resample: Whether to resample the image. When it is true, the image size will change.

method: Specify the algorithm for the change. Please refer to EnumDWT_InterpolationMethod.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v8.0+ v10.0+ v11.0+ v11.0+ v12.1+ v16.0+

ConvertToBW

Convert the specified image to black & white.

Syntax

ConvertToBW(
    index: number,
    successCallback?: () => void,
    failureCallback?: (
        errorCode: number,
        errorString: string
    ) => void
): void | boolean;

Parameters

index: Specify the index of the image to be converted. The index is 0-based.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
not supported v15.3+ v15.3+ v15.3+ v15.3+ v16.0+

ConvertToGrayScale

Convert the specified image to grayscale.

Syntax

ConvertToGrayScale(
    index: number,
    successCallback?: () => void,
    failureCallback?: (
        errorCode: number,
        errorString: string
    ) => void
): void | boolean;

Parameters

index: Specify the index of the image to be converted. The index is 0-based.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v10.0+ v10.0+ v11.0+ v11.0+ v12.1+ v16.0+

Invert

Invert the colour of the pixels on the specified image.

Syntax

Invert(
    index: number,
    successCallback?: () => void,
    failureCallback?: (
        errorCode: number,
        errorString: string
    ) => void
): void | boolean;

Parameters

index: Specify the index of the image to be inverted. The index is 0-based.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
not supported v15.3+ v15.3+ v15.3+ v15.3+ v16.0+

SetImageWidth

Change the width of the specified image by adding a margin or removing part of the image.

Syntax

SetImageWidth(
    index: number,
    width: number,
    successCallback?: () => void,
    failureCallback?: (
        errorCode: number,
        errorString: string
    ) => void
): void | boolean;

Parameters

index: Specify the index of the image to be changed. The index is 0-based.

width: Specify the new width.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v10.0+ v10.0+ v11.0+ v11.0+ v12.1+ v16.0+

Flip

Flip the specified image.

Syntax

Flip(
    index: number,
    successCallback?: () => void,
    failureCallback?: (
        errorCode: number,
        errorString: string
    ) => void
): void | boolean;

Parameters

index: Specify the index of the image in the buffer. The index is 0-based.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v6.0+ v10.0+ v11.0+ v11.0+ v12.1+ v16.0+

Mirror

Mirror the specified image.

Syntax

Mirror(
    index: number,
    successCallback?: () => void,
    failureCallback?: (
        errorCode: number,
        errorString: string
    ) => void
): void | boolean;

Parameters

index: Specify the index of the image in the buffer. The index is 0-based.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v4.0+ v10.0+ v11.0+ v11.0+ v12.1+ v16.0+

RotateLeft

Rotate the specified image 90 degrees counterclockwise.

Syntax

RotateLeft(
    index: number,
    successCallback?: () => void,
    failureCallback?: (
        errorCode: number,
        errorString: string
    ) => void
): void | boolean;

Parameters

index: Specify the index of the image in the buffer. The index is 0-based.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v4.0+ v10.0+ v11.0+ v11.0+ v12.1+ v16.0+

RotateRight

Rotate the specified image 90 degrees clockwise.

Syntax

RotateRight(
    index: number,
    successCallback?: () => void,
    failureCallback?: (
        errorCode: number,
        errorString: string
    ) => void
): void | boolean;

Parameters

index: Specify the index of the image in the buffer. The index is 0-based.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v4.0+ v10.0+ v11.0+ v11.0+ v12.1+ v16.0+

Rotate

Rotate the specified image by the specified angle.

Syntax

Rotate(
    index: number,
    angle: number,
    keepSize: boolean,
    successCallback?: () => void,
    failureCallback?: (
        errorCode: number,
        errorString: string
    ) => void
): void | boolean;

Parameters

index: Specify the index of the image in the buffer. The index is 0-based.

angle: Specify the angle to rotate the image. Positive angle means clockwise. Negative value is counter-clockwise.

keepSize: Specify whether to keep the original size of the image.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v6.0+ v10.0+ v11.0+ v11.0+ v12.1+ v16.0+

RotateEx

Rotate the specified image by the specified angle.

Syntax

RotateEx(
    index: number,
    angle: number,
    keepSize: boolean,
    method: Dynamsoft.DWT.EnumDWT_InterpolationMethod | number,
    successCallback?: () => void,
    failureCallback?: (
        errorCode: number,
        errorString: string
    ) => void
): void | boolean;

Parameters

index: Specify the index of the image in the buffer. The index is 0-based.

angle: Specify the angle to rotate the image. Positive angle means clockwise. Negative value is counter-clockwise.

keepSize: Specify whether to keep the original size of the image.

method: Specify the algorithm for the change. Please refer to EnumDWT_InterpolationMethod.

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v7.0+ v10.0+ v11.0+ v11.0+ v12.1+ v16.0+

Crop

Crop the specified image using the specified coordinates.

Syntax

Crop(
    index: number,
    left: number,
    top: number,
    right: number,
    bottom: number,
    successCallback?: () => void,
    failureCallback?: (
        errorCode: number,
        errorString: string
    ) => void
): void | boolean;

Parameters

index: Specify the index of the image in the buffer. The index is 0-based.

left: Specify the rectangle (leftmost coordinate).

top: Specify the rectangle (topmost coordinate).

right: Specify the rectangle (rightmost coordinate).

bottom: Specify the rectangle (bottommost coordinate).

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v6.0+ v10.0+ v11.0+ v11.0+ v12.1+ v16.0+

Example

//How to crop the selected area in the current image
//Register an event to get the selected rectangle coordinate
DWObject.Viewer.on("pageAreaSelected", function (sImageIndex, rect) {
  if (rect.length > 0){
      var currentRect = rect[rect.length - 1];
      _iLeft = currentRect.x;
      _iTop = currentRect.y;
      _iRight - currentRect.x + currentRect.width;
      _iBottom= currentRect.y + currentRect.height;
  }
}); 
//Crop 
if (_iLeft != 0 || _iTop != 0 || _iRight != 0 || _iBottom != 0) {
    DWObject.Crop(
        DWObject.CurrentImageIndexInBuffer, //Current image
        _iLeft, _iTop, _iRight, _iBottom
    );
} 

Remark

pageAreaSelected


Erase

Syntax

Erase a rectangular area from the specified image.

Erase(
    index: number,
    left: number,
    top: number,
    right: number,
    bottom: number,
    successCallback?: () => void,
    failureCallback?: (
        errorCode: number,
        errorString: string
    ) => void
): void | boolean;

Parameters

index: Specify the index of the image in the buffer. The index is 0-based.

left: Specify the rectangle (leftmost coordinate).

top: Specify the rectangle (topmost coordinate).

right: Specify the rectangle (rightmost coordinate).

bottom: Specify the rectangle (bottommost coordinate).

successCallback: A callback function that is executed if the request succeeds.

failureCallback: A callback function that is executed if the request fails.

  • errorCode: The error code.
  • errorString: The error string.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v6.0+ v10.0+ v11.0+ v11.0+ v12.1+ v16.0+

CopyToClipboard

Copy the specified image to the clipboard of the operating system.

Syntax

CopyToClipboard(index: number): boolean;

Parameters

index: Specify the index of the image in the buffer. The index is 0-based.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v4.0+ v10.0+ v11.0+ v11.0+ v12.1+ not supported

CutToClipboard

Cut the specified image to the clipboard of the operating system.

Syntax

CutToClipboard(index: number): boolean;

Parameters

index: Specify the index of the image in the buffer. The index is 0-based.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v4.0+ v10.0+ v11.0+ v11.0+ v12.1+ not supported

CropToClipboard

Crop a rectangular area from the specified image to the clipboard of the operating system.

Syntax

CropToClipboard(
    index: number,
    left: number,
    top: number,
    right: number,
    bottom: number
): boolean;

Parameters

index: Specify the index of the image in the buffer. The index is 0-based.

left: Specify the rectangle (leftmost coordinate).

top: Specify the rectangle (topmost coordinate).

right: Specify the rectangle (rightmost coordinate).

bottom: Specify the rectangle (bottommost coordinate).

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v4.0+ v10.0+ v11.0+ v11.0+ v12.1+ not supported

CutFrameToClipboard

Cut a rectangular area from the specified image to the clipboard of the operating system.

Syntax

CutFrameToClipboard(
    index: number,
    left: number,
    top: number,
    right: number,
    bottom: number
): boolean;

Parameters

index: Specify the index of the image in the buffer. The index is 0-based.

left: Specify the rectangle (leftmost coordinate).

top: Specify the rectangle (topmost coordinate).

right: Specify the rectangle (rightmost coordinate).

bottom: Specify the rectangle (bottommost coordinate).

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v6.0+ v10.0+ v11.0+ v11.0+ v12.1+ not supported

Usage notes

The empty area resulted from the crop/erase/cut will be filled with the colour set with BackgroundFillColor.


BackgroundFillColor

Return or set the fill colour for the empty area on an image that has been cut/cropped/erased.

Syntax

BackgroundFillColor: number;

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
v6.0+ v10.0+ v11.0+ v11.0+ v12.1+ v16.0+

Usage notes

By default the colour is white (0xffffff). The byte-ordering of the 24-bit RGB value is RRGGBB. RR represents red, GG represents green and BB represents blue.


ChangeBrightnessAsync

Change the image brightness.

Syntax

ChangeBrightnessAsync(index: number, val: number): Promise<boolean>;

Parameters

index: Specify the index of the image in the buffer. The index is 0-based.

val: Specify the brightness. Allowed values [-1000~1000]. Negative value means decrease the brightness.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
not supported v17.2+ v17.2+ v17.2+ v17.2+ v17.2+

ChangeContrastAsnyc

Change the image contrast.

Syntax

ChangeContrastAsnyc(index: number, val: number): Promise<boolean>;

Parameters

index: Specify the index of the image in the buffer. The index is 0-based.

val: Specify the contrast. Allowed values [-1000~1000]. Negative value means decrease the contrast.

Availability

ActiveX H5(Windows) H5(macOS/TWAIN) H5(macOS/ICA) H5(Linux) WASM
not supported v17.2+ v17.2+ v17.2+ v17.2+ v17.2+

Is this page helpful?

YesYes NoNo

In this article:

latest version

    • Latest Version
    • Version 17.2.1
    • Version 17.1.1
    • Version 17.0
    • Version 16.2
    • Version 16.1.1
    Change +
    © 2003–2022 Dynamsoft. All rights reserved.
    Privacy Statement / Site Map / Home / Purchase / Support