1. 程式人生 > >【FAQ合集】TWAIN掃描識別工具Dynamic Web TWAIN的程式設計程式碼問題

【FAQ合集】TWAIN掃描識別工具Dynamic Web TWAIN的程式設計程式碼問題

Dynamsoft

1.如何獲取黑白影象?

DWObject.OpenSource();
DWObject.IfShowUI = false;
DWObject.IfDisableSourceAfterAcquire = true;
DWObject.PixelType = EnumDWT_PixelType.TWPT_BW; //Black - White 
image : EnumDWT_PixelType.TWPT_BW, GRAY image: 
EnumDWT_PixelType.TWPT_GRAY, RGB 
image: EnumDWT_PixelType.TWPT_RGB
DWObject.AcquireImage();

2.如何在沒有使用者介面的情況下執行?

function BeginScan(){
    DWObject.OpenSource();
    DWObject.IfShowUI = false; //set without user interface
    DWObject.IfDisableSourceAfterAcquire = true;

    DWObject.AcquireImage();
}

function DWObject_OnPostTransfer(){
    DWObject.SaveAsBMP("C:\\temp.bmp",0);
}

3.如何只掃描紙張的某一部分?

DWObject.SelectSource();
DWObject.OpenSource();
DWObject.IfShowUI = false;
//Set Image Layout
DWObject.Unit = EnumDWT_UnitType.TWUN_INCHES;
DWObject.SetImageLayout(0, 0, 5, 5);
DWObject.AcquireImage(); 

4.如何在不顯示裝置選擇對話方塊的情況下選擇裝置?

DWObject.OpenSourceManager();

for(i = 0, i<=DWObject.SourceCount - 1,i++){
    if (DWObject.GetSourceNameItems(i) == "Specified device name")
        DWObject.SelectSourceByIndex (i);
}
//if can't find the specified source, it'll select default source DWObject.AcquireImage();

5.如何在不使用UI獲取影象時禁用進度指示器對話方塊?

DWObject.IfShowUI = false;
DWObject.IfDisableSourceAfterAcquire = true;
DWObject.OpenSource();
DWObject.IfShowIndicator = false;
DWObject.AcquireImage();

6.如何分別設定水平和垂直解析度?

DWObject.SelectSource();
DWObject.OpenSource();

//Set XRESOLUTION current value.
DWObject.Capability = 0x1118; //ICAP_XRESOLUTION
DWObject.CapType = 5; //TWON_ONEVALUE
DWObject.CapValue = 300;
if (DWObject.CapSet == false){
    alert( "Failed to set the x-resolution. " + DWObject.ErrorString);
}

//Set YRESOLUTION current value.
DWObject.Capability = 0x1119; //ICAP_YRESOLUTION
DWObject.CapType = 5; //TWON_ONEVALUE
DWObject.CapValue = 200;
if (DWObject.CapSet == false){
   alert( "Failed to set the y-resolution." + DWObject.ErrorString);
}

DWObject.AcquireImage();

7.如何上傳到Web伺服器?

DWObject = document.getElementById("dwtcontrolContainer");
//dwtcontrolContainer is the id of the Dynamic Web TWAIN on the page (An object or an embed).
function btnScan_onclick() 
{
DWObject.SelectSource();
DWObject.OpenSource();
DWObject.AcquireImage();
}
function btnUpload_onclick() 
{
var strActionPage;
var strHostIP;
var CurrentPathName = unescape(location.pathname); // get current PathName in 
plain ASCII 
var CurrentPath = CurrentPathName.substring(0, CurrentPathName.lastIndexOf("/") 
+ 1); 
strActionPage = CurrentPath + "SaveToFile.aspx"; //the ActionPage's file path
strHostIP = "localhost"; //The host's IP or name 
DWObject.HTTPPort = 80; 
DWObject.HTTPUploadThroughPost(strHostIP,0,strActionPage,"imageData.tif");
if (DWObject.ErrorCode != 0)
alert(DWObject.ErrorString);
else //succeed
alert("Image Uploaded successfully");
}

8.如何使用ADF?希望將每個文件儲存在一個單獨的檔案中。

var iDocumentCounter =0;

function BeginScan(){
    DWObject.OpenSource();

    DWObject.IfShowUI = false;
    DWObject.IfDisableSourceAfterAcquire = true;
    if(DWObject.Duplex != TWDX_NONE)
        DWObject.IfDuplexEnabled = true; //enable duplex

DWObject.IfFeederEnabled = true;
    if (DWObject.IfFeederEnabled == true){
         DWObject.XferCount = -1;

         if(DWObject.IfFeederLoaded == True)
             DWObject.AcquireImage();
    }
}

function DWObject_OnPosttransfer(){
iDocumentCounter = iDocumentCounter + 1;

if(DWObject.SaveAsBMP("C:\\Image\\" + iDocumentCounter + ".bmp", 0) == false)
    alert( DWObject.ErrorString);
}

9.我如何使用SSL?

您可以使用IfSSL屬性。下面的JavaScript示例將顯示如何使用IfSSL屬性。
function btnUpload_onclick() 
{
   DWObject.HTTPPort = 80; 
   DWObject.IfSSL = false; // if 80 is the port number of 
non-secure port

   /* 
   DWObject.HTTPPort = 443; 
   DWObject.IfSSL = true; // if 443 is the port number of secure 
port
   */

   DWObject.HTTPUploadThroughPost("127.0.0.1", 0, 
"/SaveToFile.php", "imageData.jpg");

   if (DWObject.ErrorCode != 0)
      alert(DWObject.ErrorString);
   else //succeed
     alert("Successful");
}

10.如何將新掃描的影象新增到現有的多頁TIFF檔案中?

function Scan_Click(){
   DWObject.AcquireImage();
}
function DWObject_OnPostTransfer(){
   DWObject.CloseSource();
   DWObject.IfTiffMultiPage = true;
   DWObject.SaveAsTIFF("SaveAsTIFF.tif", 0);
   if (DWObject.ErrorCode != 0)
      alert (DWObject.ErrorString);
   else //succeed
      alert ("Successful");
}

11.如何在儲存之前旋轉影象?

12.如果緩衝區中有多個影象,如何檢視指定的影象?

您可以通過更新API CurrentImageIndexInBuffer的值來檢視指定的影象或瀏覽緩衝區中的所有影象。
function NextImage_Click(){
   if (DWObject.HowManyImagesInBuffer == 0) 
   
      alert ("There is no image in buffer");

   DWObject.CurrentImageIndexInBuffer += 1;
}

13.如何進行雙面掃描?
function DuplexScan_Click(){
   DWObject.SelectSource();
   DWObject.OpenSource();
   DWObject.IfShowUI = false;
   DWObject.IfDuplexEnabled = true; //enable duplex
   DWObject.AcquireImage();
} 

14.如何以反轉顏色掃描影象?