用Visual Basic 6.0 如何调用扫描仪 Twain.dll
写得越详细越好,在线等,好用就给分

解决方案 »

  1.   

    TWAIN and Visual BasicQuestion: Is it possible to write a Windows TWAIN Application using Visual Basic or other high level programming language that doesn't allow modifying the main application's message loop?Yes, it is possible, but it will be much easier if you use one of the TWAIN ActiveX/COM controls/libraries available on the et today. The use of memory pointers, handles, TWAIN capability containers and the need to alter the main application's message loop make it difficult to use a high level language such as Visual Basic.The recommended solution to develop a Visual Basic (or other high level language) TWAIN Application is to use one of the TWAIN ActiveX/COM controls/libraries available on the et today. Some of these ActiveX controls are very well developed and would let the application use the full TWAIN programmatic functionality that TWAIN Data Sources might support - in most cases using a very simple set of ActiveX control properties, methods and events, saving the transferred images to disk files in formats easily recognized by the image/picture controls in Visual Basic and other similar languages.To develop very basic, simple, limited usage TWAIN application support, a Visual Basic application could do the following:1. Open the Data Source
    2. Set MSG_XFERCOUNT to 1
    3. Enable the Data Source modally (TW_USERINTERFACE.ModalUI set to TRUE)
    3. Start a local message loop (using PeekMessage/GetMessage and TranslateMessage
        Win32 APIs) to wait for the first message to come from the Source.
    4. If MSG_XFERREADY is received, transfer one image then end the transfer.
    5. Discard any pending transfers if there are any and disable the Data Source.
    6. This means no complex capability negotiation, just one image transfer
        per MSG_ENABLEDS/MSG_DISABLEDS sequence.
    7. If MSG_CLOSEDSREQ is received instead of MSG_XFERREADY, consider the session
        canceled and disable the Data Source. Such an application would need to load
        TWAIN_32.DLL and connect to its exported DSM_Entry. 
      

  2.   

      http://www.twain.org/docs/PerformanceWhitePaper.PDF   
        
      http://www.twain.org/docs/CapOrderForWeb.PDF   
        
      http://www.twain.org/docs/TWAINMandatory.PDF   
        
      http://www.twain.org/docs/whitepaper.htm
    在Delphi中控制扫描仪,参考一下   
        
      http://www.yesky.com/20000319/35312.shtml   
      ——————————————————————————————————   
        
      在利用Delphi开发信息管理系统时,常常要处理图象,这也是信息管理系统发展的必然趋势。怎样在Delphi中通过扫描仪获得所需的图象信息呢?不外乎有三种基本的方法:     
      通过图象处理软件,比如说Photoshop等,通过它们的扫描图象的功能,加工成一定格式的图象后再在自己的系统中利用;     
        
      通过扫描仪接口Twain.DLL   。该接口是在安装扫描仪时提供的,它实际上是一个Plugin插件,它通过一系列函数来控制扫描仪;     
        
      通过构件技术来控制扫描仪。     
      利用第一种方法能减少编程的复杂度,但是系统的集成度不高,用户使用上也不方便;第二种方法能在驱动程序级直接控制扫描仪,能在编程上提供最大的灵活性和可控性;第三种方法能充分利用Delphi的可视化构件技术,安全、灵活、自由地利用扫描仪。其实第三种方法也是建立在扫描仪接口Twain.DLL之上的。本文论述的方法就采用第三种。     
      Windows9X在其附件中提供了“映象”可选件,该附件是采用OCX构件来控制扫描仪的,共有imgEdit、imgAnntool、imgScan、imgAdmin   四个,有这四个构件基本上就能完全控制扫描仪。在Delphi中的用法如下:     
        
      在Windows9x中选择安装“映象”。(在控制面板中选择“添加/删除程序”,再选择“安装Windows”,点击“附件”复选框,然后从“详细资料”按钮中可以找到“映象”)     
        
      启动Delphi,选择“Component”菜单项下的“Import   ActiveX   Control”,这时可以看到列表中有“Wang   图象编辑控制、Wang   图象扫描控制、Wang   图象管理控制、Wang   图象缩略图控制”,选中这四项,然后点击“Install”按钮,这时在构件面板上的ActiveX舌标下就可以看到这四个构件的图标。     
      ImgScan   的主要属性:FileType:图象的文件类型(该构件支持三种:TIFF,BMP,AWD);     
      ScanTo:返回或设置被扫描图象的目的;   
        
      可取值   含义     
      0   (缺省)   显示被扫描的图象.     
      1   显示被扫描的图象并写入一个文件.     
      2   把图?   入一个文件     
      3   以模板方式把图象写入文件并显示.     
      4   以模板方式把图象写入文件     
      5   传真被扫描的图象     
        
      注意:如果取缺省值0,   
      必须和   Wang   ImgEdit   构件配合使用。   
        DestImageControl:Wang   ImgEdit构件名;   
      Zoom:图象的放缩比例   
        
      ImgScan   的主要方法:OpenScanner   :打开扫描仪;   
      CloseScanner   :关闭扫描仪;     
      StartScan   :   开始扫描;   
      StopScan   :   停止扫描   
        
        
      ImgEdit   的属性主要是控制扫描图象的分辨率、图象的宽高、是否允许对图象进行局部选   择等;其方法主要有拷贝、剪切图象到粘贴板,从粘贴板复制图象,旋转、放缩、   镜象图象;打印、保存、刷新图象等。     
      关于上述四个OCX构件的详细使用说明可在Delphi中查看其自带的帮助系统。     
        
      下面是使用这两个构件的一些例子:     
        
      procedure   Tscanf.N1Click(Sender:   TObject);   
      begin   
      ImgScan1.ShowSelectScanner;     
      //选择系统中已安装的扫描仪   
      end;   
        
      procedure   Tscanf.N2Click(Sender:   TObject);   
      begin   
        imgedit1.zoom:=100;   //设置图象的放缩因子   
        if   not   imgscan1.ScannerAvailable   then     
        //如果选择的扫描仪不可用   
        imgscan1.OpenScanner;//打开扫描仪   
        imgscan1.StartScan;   //开始扫描图象   
        imgscan1.CloseScanner;   //关闭扫描仪   
      end;   
        
        
      procedure   Tscanf.N8Click(Sender:   TObject);   
      begin   
      if   (imgedit1.IsClipboardDataAvailable     
      and   imgedit1.ImageDisplayed   )   then   
        imgedit1.ClipboardPaste(selleft,seltop);   
      //从剪贴板粘贴图象,其参数为Imgedit的显示区域的起始坐标   
      end;   
        
      procedure   Tscanf.N1801Click(Sender:   TObject);   
      begin   
        if   imgedit1.ImageDisplayed   then   
        imgedit1.Flip;   //镜象图象   
        end;   
        
      procedure   Tscanf.N901Click(Sender:   TObject);   
      begin   
      if   imgedit1.ImageDisplayed   then   
      imgedit1.RotateRight   //向右旋转图象   
      end;   
      procedure   Tscanf.N6Click(Sender:   TObject);   
      begin   
        imgedit1.DrawSelectionRect(selleft,   
      seltop,selwidth,selheight);//进行图象局部选择   
        imgedit1.ClipboardCut(selleft,seltop,   
      selwidth,selheight);//剪切所选区域   
      end;   
        
        
      注意:在DELPHI中使用Imgedit构件的拷贝和剪切功能时,会出现以下问题:     
      1、   如果把整幅图象都选中,没有任何问题;     
        
      2、   如果选择了局部区域,则拷贝和剪切的区域会发生漂移;     
        
      3、   如果DELPHI做的是MS   SQL后端数据库的客户端界面,那么在把图象内容写入数据库的图象字段中时,BDE(数据库引擎)会报错。这是DELPHI3。0和4。0的BUG,4。0的升级包可以解决这个问题。     
        
      至于第二个问题,可这样解决:在Imgedit的onSelectionRectDrawn事件中写一段代码,把选择区域的边界值保存到四个全局变量中,在拷贝和剪切之前用先前保存的变量再进行一次选择即可(当然,这一切都在后台进行的,见前面的例子)。     
        
      开发环境:DELPHI4。0,HP   ScanJet   4P扫描仪;   
      

  3.   

    最重要的是:Twain.dll----这个东东里边有些什么接口函数,这个最重要! 
      

  4.   

    Wang       图象编辑控制 等控件是在win95 和 NT4的,98以后wang都被改成柯达了,98第二版及2000之后的windows系统带的柯达控件和98第一版所带的有一点区别,winXP之后的操作系统就不带有这4个控件了。不过可以将win2000中的控件及一系列动态链接库一起迁移到XP系统中。
    我将2000下的这4个空间及支持文件做成了一个安装包,有需要的和我QQ联系:71429660