How to use methods/events

Methods

Once the Dynamsoft camera object is initialized, you can control it like a normal JS object. You can refer to our online API Documentation to check all built-in methods and events of Dynamsoft Camera SDK.

Methods are used to call the built-in functions of the Dynamsoft camera object such as captureImage, rotateRight, etc. The syntax is fairly simple:

// Method

/// <summary>
/// Rotates the image of a specified index in buffer by 90 degrees clockwise.
/// </summary>
/// <param name='index' type='int'> specifies the index of image in buffer. The index is 0-based.</param>
/// <returns type='bool'></returns>
imageViewer.image.rotateRight(0); // rotate the 1st image in the buffer by 90 degrees clockwise

Events

Events are triggered when certain trigger points are reached. For example, we have an onmouseclick event for mouse clicking, an onmouserightclick event for mouse right clicking in the built-in video viewer and image viewer, etc.

Handling Events

To use onmouseclick event in the video viewer, please refer to the sample code below:

 

<script type='text/javascript'>
if (dcsObject) {
    dcsObject.videoviewer.onmouseclick = onMouseClick;
}

function onMouseClick(imageIndex, mouseX, mouseY) { 
   /* This event onmouseclick will be triggered when the mouse clicks on the video container in video viewer. */
   /* your code goes here*/
}
</script>

In the above code, we added the JavaScript function onMouseClick() as an event listener for the event onmouseclick.

Alternatively, you can write code like this:

 
<script type='text/javascript'>
if (dcsObject) {
    dcsObject.videoviewer.onmouseclick = function (imageIndex, mouseX, mouseY) { 
        /* your code goes here*/
    }
}
</script>