C# 在平板扫描仪上,但进料器需要 如果(documentHandlingSelect!=null) { //检查文档进纸器 if((Convert.ToUInt32(documentHandlingSelect.get_Value())&;amp;amp;WIA_DPS_DOCUMENT_HANDLING_SELECT.FEEDER)!=0) { hasMorePages=((Convert.ToUInt32(documentHandlingStatus.get_Value())&;amp;amp;WIA_DPS_DOCUMENT_HANDLING_STATUS.FEED_READY)!=0); } } } } 返回图像; } /// ///获取可用WIA设备的列表。 /// /// 公共静态列表GetDevices() { 列表设备=新列表(); WIA.DeviceManager manager=新的WIA.DeviceManager(); foreach(manager.DeviceInfo中的WIA.DeviceInfo信息) { 添加(信息设备ID); } 返回装置; } } }

C# 在平板扫描仪上,但进料器需要 如果(documentHandlingSelect!=null) { //检查文档进纸器 if((Convert.ToUInt32(documentHandlingSelect.get_Value())&;amp;amp;WIA_DPS_DOCUMENT_HANDLING_SELECT.FEEDER)!=0) { hasMorePages=((Convert.ToUInt32(documentHandlingStatus.get_Value())&;amp;amp;WIA_DPS_DOCUMENT_HANDLING_STATUS.FEED_READY)!=0); } } } } 返回图像; } /// ///获取可用WIA设备的列表。 /// /// 公共静态列表GetDevices() { 列表设备=新列表(); WIA.DeviceManager manager=新的WIA.DeviceManager(); foreach(manager.DeviceInfo中的WIA.DeviceInfo信息) { 添加(信息设备ID); } 返回装置; } } },c#,wia,twain,image-scanner,C#,Wia,Twain,Image Scanner,您可以在我实现的代码中看到。首先,非常感谢Miljenko Barbir提供的上述解决方案,它非常有效 我想补充一点,如果您想要零对话框,您可以使用(来自Milijenko的演示代码) 而不是 WIA.ImageFile image = (WIA.ImageFile)wiaCommonDialog.ShowTransfer(item, wiaFormatBMP, false); 这基本上也会删除进度条,因此您可以在没有任何对话框的情况下进行扫描。您认为如果您试图避免出现任何UI,调用GetIt

您可以在我实现的代码中看到。

首先,非常感谢Miljenko Barbir提供的上述解决方案,它非常有效

我想补充一点,如果您想要零对话框,您可以使用(来自Milijenko的演示代码)

而不是

WIA.ImageFile image = (WIA.ImageFile)wiaCommonDialog.ShowTransfer(item, wiaFormatBMP, false);

这基本上也会删除进度条,因此您可以在没有任何对话框的情况下进行扫描。

您认为如果您试图避免出现任何UI,调用
GetItemsFromUI
可能是问题的根源?顺便说一句,这是使用Microsoft Windows Image Acquisition 1.01类型库完成的,但是如果它解决了这个问题,欢迎使用任何其他库。@Damien\u异信者:LOL,这一定是问题所在,但是,还有什么选择……难道你不能只使用
wiaRoot.Children
?@Gabe:wiaRoot.Children,我能用
wiaRoot.Children
做什么?这真的帮助我在修改代码时不使用任何UI进行扫描。非常感谢。@Greg,非常感谢。这节省了我的时间
using System;
using System.Collections.Generic;
using System.IO;
using System.Drawing;

namespace WIATest
{
    class WIAScanner
    {
        const string wiaFormatBMP = "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}";

        class WIA_DPS_DOCUMENT_HANDLING_SELECT
        {
            public const uint FEEDER = 0x00000001;
            public const uint FLATBED = 0x00000002;
        }

        class WIA_DPS_DOCUMENT_HANDLING_STATUS
        {
            public const uint FEED_READY = 0x00000001;
        }

        class WIA_PROPERTIES
        {
            public const uint WIA_RESERVED_FOR_NEW_PROPS = 1024;
            public const uint WIA_DIP_FIRST = 2;
            public const uint WIA_DPA_FIRST = WIA_DIP_FIRST + WIA_RESERVED_FOR_NEW_PROPS;
            public const uint WIA_DPC_FIRST = WIA_DPA_FIRST + WIA_RESERVED_FOR_NEW_PROPS;
            //
            // Scanner only device properties (DPS)
            //
            public const uint WIA_DPS_FIRST = WIA_DPC_FIRST + WIA_RESERVED_FOR_NEW_PROPS;
            public const uint WIA_DPS_DOCUMENT_HANDLING_STATUS = WIA_DPS_FIRST + 13;
            public const uint WIA_DPS_DOCUMENT_HANDLING_SELECT = WIA_DPS_FIRST + 14;
        }

        /// <summary>
        /// Use scanner to scan an image (with user selecting the scanner from a dialog).
        /// </summary>
        /// <returns>Scanned images.</returns>
        public static List<Image> Scan()
        {
            WIA.ICommonDialog dialog = new WIA.CommonDialog();
            WIA.Device device = dialog.ShowSelectDevice(WIA.WiaDeviceType.UnspecifiedDeviceType, true, false);

            if (device != null)
            {
                return Scan(device.DeviceID);
            }
            else
            {
                throw new Exception("You must select a device for scanning.");
            }
        }

        /// <summary>
        /// Use scanner to scan an image (scanner is selected by its unique id).
        /// </summary>
        /// <param name="scannerName"></param>
        /// <returns>Scanned images.</returns>
        public static List<Image> Scan(string scannerId)
        {
            List<Image> images = new List<Image>();

            bool hasMorePages = true;
            while (hasMorePages)
            {
                // select the correct scanner using the provided scannerId parameter
                WIA.DeviceManager manager = new WIA.DeviceManager();
                WIA.Device device = null;

                foreach (WIA.DeviceInfo info in manager.DeviceInfos)
                {
                    if (info.DeviceID == scannerId)
                    {
                        // connect to scanner
                        device = info.Connect();
                        break;
                    }
                }

                // device was not found
                if (device == null)
                {
                    // enumerate available devices
                    string availableDevices = "";
                    foreach (WIA.DeviceInfo info in manager.DeviceInfos)
                    {
                        availableDevices += info.DeviceID + "n";
                    }

                    // show error with available devices
                    throw new Exception("The device with provided ID could not be found. Available Devices:n" + availableDevices);
                }

                WIA.Item item = device.Items[1] as WIA.Item;

                try
                {
                    // scan image
                    WIA.ICommonDialog wiaCommonDialog = new WIA.CommonDialog();
                    WIA.ImageFile image = (WIA.ImageFile)wiaCommonDialog.ShowTransfer(item, wiaFormatBMP, false);

                    // save to temp file
                    string fileName = Path.GetTempFileName();
                    File.Delete(fileName);
                    image.SaveFile(fileName);
                    image = null;

                    // add file to output list
                    images.Add(Image.FromFile(fileName));
                }
                catch (Exception exc)
                {
                    throw exc;
                }
                finally
                {
                    item = null;

                    //determine if there are any more pages waiting
                    WIA.Property documentHandlingSelect = null;
                    WIA.Property documentHandlingStatus = null;

                    foreach (WIA.Property prop in device.Properties)
                    {
                        if (prop.PropertyID == WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_SELECT)
                            documentHandlingSelect = prop;

                        if (prop.PropertyID == WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_STATUS)
                            documentHandlingStatus = prop;
                    }

                    // assume there are no more pages
                    hasMorePages = false;

                    // may not exist on flatbed scanner but required for feeder
                    if (documentHandlingSelect != null)
                    {
                        // check for document feeder
                        if ((Convert.ToUInt32(documentHandlingSelect.get_Value()) &amp;amp;amp;amp; WIA_DPS_DOCUMENT_HANDLING_SELECT.FEEDER) != 0)
                        {
                            hasMorePages = ((Convert.ToUInt32(documentHandlingStatus.get_Value()) &amp;amp;amp;amp; WIA_DPS_DOCUMENT_HANDLING_STATUS.FEED_READY) != 0);
                        }
                    }
                }
            }

            return images;
        }

        /// <summary>
        /// Gets the list of available WIA devices.
        /// </summary>
        /// <returns></returns>
        public static List<string> GetDevices()
        {
            List<string> devices = new List<string>();
            WIA.DeviceManager manager = new WIA.DeviceManager();

            foreach (WIA.DeviceInfo info in manager.DeviceInfos)
            {
                devices.Add(info.DeviceID);
            }

            return devices;
        }

    }
}
// show scanner view 
guif.ShowUI = 0;
guif.ModalUI = 0;
WIA.ImageFile image = item.Transfer(wiaFormatBMP);
WIA.ImageFile image = (WIA.ImageFile)wiaCommonDialog.ShowTransfer(item, wiaFormatBMP, false);