图形/图像
Twain和Wia两个驱动的区别及相关方法代码
2017-02-05 14:33:04

Twain和Wia两个驱动的区别及相关方法代码

 

扫描的部分代码及方法 

1. Twain和Wia两个驱动的区别  TWAIN是一项重要的接口标准,为软件开发商和硬件设备生产厂商之间提供了一个统一的规范,以有效地避免系统及设备之间的不兼容问题。 在计算机发展初期,计算机与周边外围设备之间没有任何接口标准,每一种硬件设备需要与计算机相连时,必须针对系统开发相应的驱动模块。由于扫描仪型号的不同,每种扫描仪都有自己相对应的驱动方式和指令集,扫描仪厂商必须为每一款扫描仪编写相应的驱动模块。这不仅费时费力,而且由于新的扫描仪不断推出,驱动模块的开发始终处于被动地位。同时,随着软件的不断发展,扫描仪厂商也面临着设备是否支持丰富的应用软件的问题。另一方面,从软件开发商的角度来看,软件的开发如果缺少硬件设备的支持,势必会使得软件的应用范围受到极大的制约,限制软件的普及和发展。因此,由于软、硬件的迅速发展,不管是硬件生产厂商还是软件开发商,都迫切需要建立专门的标准,以方便硬件设备和应用系统软件之间的信息数据传输和交换。TWAIN标准就是在这个背景下应运而生的。  TWAIN标准的建立,为软件开发商和硬件生产厂家提供了统一的连接规范,避免了重复开发和系统设备不兼容的问题。  WIA是Windows ImageAcquisition的缩写,可直接翻译为:Windows图像采集系统。这是windows XP加入的一个新功能,该功能主要包括了indowsXP对图像设备的支持以及对图像信息的处理编辑等功能。  微软公司可以说是靠图形界面的操作系统Windows而发家的,但具有讽刺意味的是,长久以来,Windows在图形图象处理领域内却无可以称道的亮点。记得早几年用扫描仪,驱动程序是由厂家开发的,应用程序也是厂商附送的。那时,Windows里面与图形处理沾边的程序,大概就是那个解决不了多大问题的“画笔”了。也许是认为市场已经成熟。也许是大而全的方针使然,在Windows xp中,微软引入了WIA体系,使Windows操作系统在支持图形图像处理方面有了很大飞跃。WIA是Windows Image Acquisition的缩写,即Windows图像采集系统。该系统涵盖了从图形采集设备支持到编辑排版打印的整个过程。  WIA有点类似于TWAIN的标准。它也是要求硬件厂商、软件开发商在开发新产品时,遵守这个标准,以避免了重复开发和系统设备不兼容的问题。 

2.扫描例子: 

 

1.     先从网上下载Kodak组件,总共有十来个.dll .OCX文件,我们只需用到其中的两个就OK了。 

2.      打开你的项目,先引用IMGEDIT.OCX和IMGSCAN.OCX。(如果引用时有问题,得在“运行”里用命令“regsvr32.exe ”执行一下)。  

3.     在开始位置引用命名空间:using ScanLibCtl;  

4.     在工具箱,选择项里添加控件“kodak图像扫描控件”,默认名称是axImgScan1。  5.好了,以上弄好后就可以开始写代码了:  axImgScan1.ShowSelectScanner();//选择扫描仪

 

int ll_rtn = axImgScan1.OpenScanner(); //打开扫描仪  if (ll_rtn == 0)  {  

     if (axImgScan1.ScannerAvailable() == true)//判断扫描仪是否可用       { 

          axImgScan1.MultiPage = true;//是否多页  

          axImgScan1.PageCount = axImgScan1.PageCount + 1;            string pathGen = @"f:/aaa";  

          string paths = pathGen+"\\app.path" + "UN";            axImgScan1.Image = paths;  

          axImgScan1.FileType = FileTypeConstants.BMP_Bitmap;//设置文件类型            axImgScan1.CompressionType = CompressionTypeConstants.JPEG;            axImgScan1.ScanTo = ScanToConstants.DisplayAndUseFileTemplate; 

          axImgScan1.SetPageTypeCompressionOpts(CompPreferenceConstants.GoodDisplay,ImageTypeConstants.BlackAndWhite1Bit, CompTypeConstants.JPEGCompression, CompInfoConstants.G31DFaxRBO);            axImgScan1.StopScanBox = false;  

          axImgScan1.ShowSetupBeforeScan = true;//是否在扫描前显示设置界面            axImgScan1.Show();  

          ll_rtn = axImgScan1.StartScan();//开始扫描            if (ll_rtn == 9254 || ll_rtn == 0) { }           else            {  

               MessageBox.Show("扫描仪没有正确连接或扫描控件已破坏,请检查!", "系统提示");            }  

          axImgScan1.CloseScanner(); //关闭扫描仪 }            

 

else

 

 {  

               MessageBox.Show( "扫描仪没有正确连接,请重新设置!","系统提示");            }       }  

     else if (ll_rtn == 9219)       {  

          MessageBox.Show("系统没有安装扫描仪或扫描仪没有正确连接!", "系统提示");       }    

3.例句: Abstract 

In Windows imaging applications, the most used API for scanning is TWAIN www.twain.org. Unfortunately, the new .NET Framework has no built-in support for TWAIN. So we have to work with the interop methods of .NET to access this API. This article doesn't explain this interop techniques, and good knowledge of the TWAIN 1.9 specifications is assumed! The sample code included doesn't present a finished library, only some essential steps for a minimal TWAIN adaption to .NET applications. Details 

First step was to port the most important parts of TWAIN.H, these are found in TwainDefs.cs. The real logic for calling TWAIN is coded in the class Twain, in file TwainLib.cs.. As the TWAIN API is exposed by the Windows DLL, twain_32.dll, we have to use the .NET DllImport mechanism for interop with legacy code. This DLL has the central DSM_Entry(), ordinal #1 function exported as the entry point to TWAIN. This call has numerous parameters, and the last one is of variable type! It was found to be best if we declare multiple variants of the call like: [DllImport("twain_32.dll", EntryPoint="#1")] private static extern TwRC DSMparent(     [In, Out] TwIdentity origin,     IntPtr zeroptr, 

    TwDG dg, TwDAT dat, TwMSG msg,