Scaning multiple pages using WIA on windows 7
Asked Answered
C

1

7

I am trying to scan a few pages from the feeder, although the scanner automatically scans all the pages when I call ShowTransfer function (without using a loop), I am getting back only the first page.

what am I doing wrong?

here's my code:

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

            if (pages > 1)
            {
                // Set to feeder
                SetWIAProperty(device.Properties, 44, 1);
            }

            SetWIAProperty(device.Properties, WIA_DEVICE_PROPERTY_PAGES_ID, 1);

            AdjustScannerSettings(item, 150, 0, 0, 1250, 1700, 0, 0, 1);
            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;
            }
Communard answered 24/2, 2020 at 7:40 Comment(1)
#2615649Cas
A
3

I think this link is doing what you want to do

http://forums.codeguru.com/showthread.php?439027-Windows-Image-Acquisition-(WIA)-Code

Basically, you need to check after saving off each page to see if there are more pages and keep looping

                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);
                    }
                }
Ancillary answered 27/2, 2020 at 7:22 Comment(4)
When the line of ShowTransfer() get Executed, the scanner scan all the pages, So if I'll implement a loop - at its second iteration it would throw an exception (the feeder is empty). If there is a way to force the scanner to scan only one page for ShowTransfer() call, I could use this code.Communard
Take a look at this question - if I'm not mistaken it has the solution to scan one page at a time.Mocha
Also, it looks like if you called ShowTransfer again it would pull the next page from the device memory rather than initiate new scan (although I might be wrong). As a side note, I recall something about having to set Item properties first, and only then Device properties, otherwise it does not work. But I can't find any reference to that information at the moment.Mocha
Found it. "After much experimentation I discovered a solution. I had been setting device properties and then setting item properties before requesting the scan. Switching the order - item then device - made everything work."Mocha

© 2022 - 2024 — McMap. All rights reserved.