Load local image(s) into viewer

Preparation

First of all, bear in mind that as a lightweight component running in web browsers, Dynamic Web TWAIN is only designed to deal with the most basic images in the following formats: BMP, JPEG, PNG, TIFF and PDF. We only guarantee that images generated by Dynamic Web TWAIN can be successfully loaded. If you are trying to load an image that was not generated by Dynamic Web TWAIN, you can check out this article.

Calling the methods

With Dynamic Web TWAIN, you can load local images with the methods LoadImage() or LoadImageEx(). Below is a simple code snippet:

DWObject.LoadImage("C:\\WebTWAIN\\Images\\ImageData.jpg", optionalAsyncSuccessFunc, <a name="OLE_LINK669"></a><a name="OLE_LINK668"></a>optionalAsyncFailureFunc);
/* ImageType: JPG */
DWObject.LoadImageEx("C:\\WebTWAIN\\Images\\ImageData.jpg", EnumDWT_ImageType.IT_JPG, optionalAsyncSuccessFunc, optionalAsyncFailureFunc); 
/* Callback functions for async APIs */
function optionalAsyncSuccessFunc(){
    console.log('successful');
}
function optionalAsyncFailureFunc(errorCode, errorString){
    alert(errorString);
}

Please note that the last two parameters optionalAsyncSuccessFunc and optionalAsyncFailureFunc are optional callback functions.

As you can see, you need to provide the complete file path in order to load an image. This is somewhat clumsy especially when you need to load more than one image. But no worries, Dynamic Web TWAIN can open a "Select File…" dialog for you to locate the image(s) you want to load. And like other properties and methods, it's very easy to use. Below is a code snippet:

DWObject.IfShowFileDialog = true;
/* ImageType: ALL (BMP, JPG, PNG, PDF, TIFF) */
DWObject.LoadImageEx("", EnumDWT_ImageType.IT_ALL);

Please note that the second parameter "ImageType" in the method LoadImageEx() would determine the file filter in the "Select File…" dialog.

image022

Is this page helpful?

Leave a Reply

Your email address will not be published.