【FAQ合集】TWAIN扫描识别工具Dynamic Web TWAIN的编程代码问题


发布者 Harriet666  发布时间 1510217364852
关键字 分享 
Dynamic Web TWAIN中文介绍免费下载资源教程示例DEMO
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.如何在保存之前旋转图像?

您可以使用RotateLeft方法和RotateRight方法。

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.如何以反转颜色扫描图像?

您可以使用PixelFlavor属性。

2017慧都十四周年狂欢搞事情!砸金蛋100%抽现金红包、满额豪送iPhone X、iPhone 8、DevExpress汉化免费送、团队升级培训套包劲省10万元......更多惊喜等您来探索!









  开源的 OurJS
OurJS开源博客已经迁移到 OnceOA 平台。

  关注我们
扫一扫即可关注我们:
OnceJS

OnceOA