none
adf scanning using WIA ... only one image saved!!!

    Question

  • 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;
                    var device = this._deviceInfo.Connect();
                    const string wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}";
                    var item = device.Items[1];
                    ImageFile [] imageFile = new ImageFile[9999];
                    while (hasMorePages)
                    {
                        try
                        {
                            imageFile[numPages] = (ImageFile)item.Transfer(wiaFormatJPEG);
                            item = null;
                            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; 
                            if (documentHandlingSelect != null)
                            {
                                
                                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 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;
          
            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;
        }


    zigzago




    • Edited by zigzago Monday, June 4, 2012 4:55 PM
    Monday, June 4, 2012 7:00 AM

All replies

  • i have the same problem ...... scane only one image
    Monday, June 4, 2012 9:44 AM
  • Hi zigzago,

    Welcome to the MSDN forum.

    I think you can check the below thread which discussing the similar issue.

    How can I get my app to fetch more than one page from a WIA scanner with an ADF?

    http://social.msdn.microsoft.com/forums/en-us/csharpgeneral/thread/76C4CD4E-0407-4226-BC6B-063AB4C033AC

    Have a nice day.


    Bob Shen [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, June 6, 2012 9:37 AM
    Moderator
  • well , this can't be applied on windows 7 i think because  this version is older than the one in  win 7, i don't know why is it scanning the 1st page only at least if there any code to capture from the adf to images then it will be very well.

    zigzago

    Tuesday, June 12, 2012 6:47 AM
  • Hi zigzago,

    You can check this:

    a small class library that allows you to use Windows® Image Acquisition 2.0 lib to scan multiple images from scanners with an auto document feeder

    http://adfwia.codeplex.com/

    Have a nice day.


    Bob Shen [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, June 13, 2012 7:11 AM
    Moderator
  •    

    In the following Feed_Ready is set to 1.

    class WIA_DPS_DOCUMENT_HANDLING_STATUS
       
    {
           
    public const uint FEED_READY = 0x00000001;
       
    }
    When I execute the following block,
    documentHandlingStatus.get_Value() returns 3. When you perform bitwise & with feed ready it returns 1 and hasMorePages is set to true.

     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);
     
    }
    My Question is : How do we know what 3 stands for? How do I know what are the constant values that
    WIA_DPS_DOCUMENT_HANDLING_STATUS return and what it stands for? I have tried searching and all i found is description of what status can be. I need to know the constant values that map to different status.

    Please Help!!


    AmeeraSajid


    Tuesday, July 31, 2012 7:53 AM
  • Hi AmeeraSajid,

    I am facing the same issue as yours. Did you by any chance found the solution for this? I know this has been an old post where you would have forgotten as well. But I am just taking my chance to find the solution for this issue. Your help will be highly appreciated.

    Thanks, Kiran

    Thursday, May 11, 2017 6:58 AM