如何一键扫描所有页面如下:
How to scan all pages with one click as below:
我有下面的代码可以扫描所有文件。它有效,但问题是当所有论文完成时,它显示错误:
Exception User-Unhandeled System.runtime.InterpService.COMEException: Exception From HRESULT:0*80210003
属于这一行:
var imgFile = (ImageFile)ScanerItem.Transfer();
我该如何解决?
这是代码:
public async void button1_Click(object sender, EventArgs e)
{
try
{
object[] items = await Task.Run<object[]>(() =>
{
var deviceManager = new DeviceManager();
List<object> result = new List<object>();
for (int i = 1; i <= deviceManager.DeviceInfos.Count; i++) // Loop Through the get List Of Devices.
{
if (deviceManager.DeviceInfos[i].Type != WiaDeviceType.ScannerDeviceType) // Skip device If it is not a scanner
{
continue;
}
//new
result.Add(deviceManager.DeviceInfos[i].Properties["Name"].get_Value());
}
return result.ToArray();
});
foreach (var item in items)
{
lstListOfScanner.Items.Add(item);
}
}
catch (COMException ex)
{
MessageBox.Show(ex.Message);
}
bool continueScanning2 = true;
try
{
await Task.Run(() =>
{
var deviceManager = new DeviceManager();
DeviceInfo AvailableScanner = null;
while (continueScanning2)
{
string name2 = Guid.NewGuid().ToString().Replace("-", "") + ".jpg";
var Path = @"C:\Users\...\Desktop\test\" + name2; // save the image in some path with filename.
pictureBox1.ImageLocation = Path;
bitmap.Save(Path, System.Drawing.Imaging.ImageFormat.Jpeg);
}
});
}
catch (COMException ex)
{
MessageBox.Show(ex.Message);
}
此 microsoft page 上提供的错误代码说明说
WIA_ERROR_PAPER_EMPTY
There are no documents in the document feeder.
并且您确认在扫描所有文件时显示错误。
在 catch
块中,您可以检查错误代码并以您认为合适的方式处理遇到 WIA_ERROR_PAPER_EMPTY 错误的情况:
catch (COMException ex)
{
uint errorCode = (uint)ex.ErrorCode;
if (errorCode == 0x80210003)
{
// handle "There are no documents in the document feeder"
}
else
{
MessageBox.Show(ex.Message);
}
}
我有下面的代码可以扫描所有文件。它有效,但问题是当所有论文完成时,它显示错误:
Exception User-Unhandeled System.runtime.InterpService.COMEException: Exception From HRESULT:0*80210003
属于这一行:
var imgFile = (ImageFile)ScanerItem.Transfer();
我该如何解决? 这是代码:
public async void button1_Click(object sender, EventArgs e)
{
try
{
object[] items = await Task.Run<object[]>(() =>
{
var deviceManager = new DeviceManager();
List<object> result = new List<object>();
for (int i = 1; i <= deviceManager.DeviceInfos.Count; i++) // Loop Through the get List Of Devices.
{
if (deviceManager.DeviceInfos[i].Type != WiaDeviceType.ScannerDeviceType) // Skip device If it is not a scanner
{
continue;
}
//new
result.Add(deviceManager.DeviceInfos[i].Properties["Name"].get_Value());
}
return result.ToArray();
});
foreach (var item in items)
{
lstListOfScanner.Items.Add(item);
}
}
catch (COMException ex)
{
MessageBox.Show(ex.Message);
}
bool continueScanning2 = true;
try
{
await Task.Run(() =>
{
var deviceManager = new DeviceManager();
DeviceInfo AvailableScanner = null;
while (continueScanning2)
{
string name2 = Guid.NewGuid().ToString().Replace("-", "") + ".jpg";
var Path = @"C:\Users\...\Desktop\test\" + name2; // save the image in some path with filename.
pictureBox1.ImageLocation = Path;
bitmap.Save(Path, System.Drawing.Imaging.ImageFormat.Jpeg);
}
});
}
catch (COMException ex)
{
MessageBox.Show(ex.Message);
}
此 microsoft page 上提供的错误代码说明说
WIA_ERROR_PAPER_EMPTY
There are no documents in the document feeder.
并且您确认在扫描所有文件时显示错误。
在 catch
块中,您可以检查错误代码并以您认为合适的方式处理遇到 WIA_ERROR_PAPER_EMPTY 错误的情况:
catch (COMException ex)
{
uint errorCode = (uint)ex.ErrorCode;
if (errorCode == 0x80210003)
{
// handle "There are no documents in the document feeder"
}
else
{
MessageBox.Show(ex.Message);
}
}