WIA C#中传输功能的问题

问题描述 投票:0回答:3

我有以下代码的问题。我想通过单击WinForms C#应用程序中的按钮来扫描文档。

我使用WIA,Visual studio和扫描仪Fujitsu N7100A与Windows 8一起使用。我正在使用WIA在线教程。

但该程序没有按预期运行。它似乎在Transfer方法中被打破了。

            // Create a DeviceManager instance 
            var deviceManager = new DeviceManager();
            // Create an empty variable to store the scanner instance
            DeviceInfo firstScannerAvailable = null;
            // Loop through the list of devices to choose the first available 
            AddLogs(deviceManager.DeviceInfos.Count.ToString(), filename);
            foreach (DeviceInfo d in deviceManager.DeviceInfos)
            {
                if (d.Type == WiaDeviceType.ScannerDeviceType)
                {
                    firstScannerAvailable = d;
                }
            }
            // Connect to the first available scanner 
            var device = firstScannerAvailable.Connect();
            // Select the scanner 
            var scannerItem = device.Items[0];
            // Retrieve a image in JPEG format and store it into a variable 
            var imageFile = (ImageFile)scannerItem.Transfer(FormatID.wiaFormatPNG);
            //Save the image in some path with filename 
            var path = @"C:\Documents\scan.png";
            if (File.Exists(path))
            {
                File.Delete(path);
            }
            // Save image ! 
            imageFile.SaveFile(path);

我只需删除日志文件中添加的行。

c# windows wia
3个回答
0
投票

这更像是一种解决方法,因为我不知道你的扫描仪。

我会假设所有扫描仪都有一个驱动器,用于存储扫描文档,就像我的一样。所以我建议您阅读所有可用的驱动器循环检查DriveType和VolumeLabel,然后读取它的文件并将文档复制到您想要的位置

像这样的东西:

foreach (var item in DriveInfo.GetDrives())
        {
            //VolumeLabel differs from a scanner to another
            if (item.VolumeLabel == "Photo scan" && item.DriveType == DriveType.Removable)
            {
                foreach (var obj in Directory.GetFiles(item.Name))
                {
                    File.Copy(obj, "[YOUR NEW PATH]");
                    break;
                }
                break;
            }
        }

0
投票

最终TWAIN应用程序可与此扫描仪配合使用。我将与之合作。我不是说为什么这与TWAIN合作而不是与WIA合作,而是现实。对不起浪费时间。谢谢你的答案。祝你今天愉快。


0
投票

我目前正在解决这个问题。似乎N7100A驱动程序将Pagesdevice属性设置为0,这应该意味着连续扫描,但传输方法无法处理此值。您必须将该属性设置为1

var pages = 1;

// Not all devices have this property, but Fujitsu N7100A has.
device.Properties["Pages"]?.set_Value(ref pages);
© www.soinside.com 2019 - 2024. All rights reserved.