adf扫描问题 [英] adf scanning problem

查看:91
本文介绍了adf扫描问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

打招呼,​​我对adf扫描的问题是代码中的传输方法(带下划线的&粗体)一次占用了扫描仪中的所有纸张,在此语句正确运行后将不进行其余检查如我所愿.该语句仅占用一页,而忽略其他页面,请检查我的代码并告诉我是否有任何事情要做.



Greetings my problem with adf scanning is that the transfer method (the underlined & bold) in the code is taking all the papers in the scanner at one time with won''t make the rest of checks after this statement running correctly as i want . this statement also takes only one page and ignore the others, please check my code and tell me if is there any thing to do.



class Scanner
    {
        private readonly DeviceInfo _deviceInfo;

        public Scanner(DeviceInfo deviceInfo)
        {
            this._deviceInfo = deviceInfo;
        }
        public override string ToString()
        {
            return this._deviceInfo.Properties["Name"].get_Value();
        }

        Image[] Img_aft = new Image[9999];

        public int Scan(int numPages,int id,string name)
        {
            
                bool hasMorePages = true;
                int begin = numPages;
                int x = 0;
               // int numPages = 0;
                // Connect to the device
                var device = this._deviceInfo.Connect();
                const string wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}";
                // Start the scan
                var item = device.Items[1];
                ImageFile [] imageFile = new ImageFile[9999];
                while (hasMorePages)
                {
                    try
                    {
                        imageFile[numPages] = (ImageFile)item.Transfer(wiaFormatJPEG);
                        item = null;
                        //determine if there are any more pages waiting
                        Property documentHandlingSelect = null;
                        Property documentHandlingStatus = null;
                        foreach (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;
                        }

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




                        var path = @"d:\archive\" + DateTime.Now.ToString().Replace('/', '-').Replace(':', '-').Substring(0, 19) + "" + numPages + ".jpeg";
                        if (File.Exists(path))
                        {
                            File.Delete(path);
                        }
                        imageFile[numPages].SaveFile(path);
                        Img_aft[numPages] = Image.FromFile(path);
                        MemoryStream ms = new MemoryStream();
                        Img_aft[numPages].Save(ms, ImageFormat.Jpeg);
                        Byte[] bytBLOBData = new Byte[ms.Length];
                        ms.Position = 0;
                        ms.Read(bytBLOBData, 0, Convert.ToInt32(ms.Length));
                        new DB().ApplyNonQuery("insert into [File] ([file_name] ,[file] ,[item_id])values('" + name + "" + numPages + "',@image," + id + ")", bytBLOBData, "@image");


                        x++;
                        numPages++;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: " + ex.Message);
                    }
                }
              
                
                //// Return the imageFile
                //return imageFile;
                return x;
        }
    }

    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;
    }

    class WIA_ERRORS
    {
        public const uint BASE_VAL_WIA_ERROR = 0x80210000;
        public const uint WIA_ERROR_PAPER_EMPTY = BASE_VAL_WIA_ERROR + 3;
    }

推荐答案

plz我也遇到同样的问题……只扫描一张图像
plz i have the same problem ... scan only one image


这篇关于adf扫描问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆