WIA是基于COM技术的,直接引用COM的DLL即可。
我问过商家,现在WIA是可以通过TWAIN进行驱动的。但是代码是不同的。
<span style="font-size:12px;"> ImageFile imageFile = null;
CommonDialogClass cdc = new WIA.CommonDialogClass();
try
{
imageFile = cdc.ShowAcquireImage(WIA.WiaDeviceType.ScannerDeviceType,
WIA.WiaImageIntent.TextIntent,
WIA.WiaImageBias.MaximizeQuality,
"{00000000-0000-0000-0000-000000000000}",
true,
true,
false);
}
catch (System.Runtime.InteropServices.COMException)
{
imageFile = null;
}
if (imageFile != null)
{
string fileName = Application.ExecutablePath + @"cache.bmp";
imageFile.SaveFile(fileName);
using (FileStream stream = new FileStream(fileName, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
pictureBox1.Image = Image.FromStream(stream);
}
File.Delete(fileName);
}</span>
就是这样,但是执行出错。异常来自 HRESULT:0x80210015
详细的错误代码如下:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms630183(v=vs.85).aspx