我希望有人遇到过这种情况-我正在尝试使用WIA从文档扫描仪捕获图像,我想使用FEEDER进行多篇论文,并且我正在使用发生错误的代码和以下代码: 我能够成功连接到扫描仪,查询名称,制造商等。
{
int pages = 0;
bool hasMorePages = false;
string[] sourceFiles = new string[100];
WIA.CommonDialog WiaCommonDialog = new WIA.CommonDialog();
try
{
do
{
//Connect to Device
Device wia = Connect();
WIA.Item item = wia.Items[1] as WIA.Item;
//Setup ADF
if ((useAdf) || (duplex))
SetupADF(wia, duplex);
//Setup Page Size
// SetupPageSize(wia, rotatePage, A4, DPI, item);
WIA.ImageFile imgFile = null;
WIA.ImageFile imgFile_duplex = null; //if duplex is setup, this will be back page
//imgFile = (WIA.ImageFile)item.Transfer(WIA.FormatID.wiaFormatJPEG);
imgFile = (ImageFile)WiaCommonDialog.ShowTransfer(item, wiaFormatJPEG, false);
//If duplex page, get back page now.
if (duplex)
{
imgFile_duplex = (ImageFile)WiaCommonDialog.ShowTransfer(item, wiaFormatJPEG, false);
}
string varImageFileName = filepath + "\\Scanned" + ".jpeg";
Delete_File(varImageFileName); //if file already exists. delete it.
imgFile.SaveFile(varImageFileName);
using (var src = new System.Drawing.Bitmap(varImageFileName))
using (var bmp = new System.Drawing.Bitmap(1000, 1000, System.Drawing.Imaging.PixelFormat.Format32bppPArgb))
using (var gr = System.Drawing.Graphics.FromImage(bmp))
{
gr.Clear(System.Drawing.Color.Blue);
gr.DrawImage(src, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height));
gr.DrawString("This is vivek", new System.Drawing.Font("Arial", 15, System.Drawing.FontStyle.Regular), System.Drawing.SystemBrushes.WindowText, new System.Drawing.Point(550, 20));
bmp.Save(System.Configuration.ConfigurationSettings.AppSettings["Path"] + "test" + pages + ".jpeg", System.Drawing.Imaging.ImageFormat.Png);
////string imgPath = "test" + pages + ".tiff";
////sourceFiles[pages] = imgPath;
//mergeTiffPages(string str_DestinationPath, string[] sourceFiles)
}
mergeTiffPages(@"D:\Test\", sourceFiles);
string varImageFileName_duplex;
if (duplex)
{
varImageFileName_duplex = filepath + "\\Scanned-" + pages.ToString() + ".tiff";
Delete_File(varImageFileName_duplex); //if file already exists. delete it.
imgFile_duplex.SaveFile(varImageFileName);
}
//Check with scanner to see if there are more pages.
if (useAdf || duplex)
{
hasMorePages = HasMorePages(wia);
pages++;
}
}
while (hasMorePages);
}
catch (System.Runtime.InteropServices.COMException ex)
{
//throw new System.Exception(CheckError((uint)ex.ErrorCode));
}
}
此行引发异常
imgFile = (ImageFile)WiaCommonDialog.ShowTransfer(item, wiaFormatJPEG, false);