Dynamic Web TWAIN: How to get the coordinates info of the selected area on an image

In many cases, you might want to edit a certain area of an image. To do this, typically you need to first get the coordinates for that area. This can be done by selecting the area with your mouse and then read the coordinates in the callback function for the event OnImageAreaSelected.

Code Snippet

DWObject.RegisterEvent('OnImageAreaSelected', function (sImageIndex, left, top, right, bottom) {
    ileft = left;
    iright = right;
    itop = top;
    ibottom = bottom;
});
function btnCrop(){
    if (ileft != 0 || itop != 0 || iright != 0 || ibottom != 0) {
        DWObject.Crop(DWObject.CurrentImageIndexInBuffer, ileft, itop, iright, ibottom);
        ileft = 0;
        iright = 0;
        itop = 0;
        ibottom = 0;
    }
}