C# WIA with Automatic Document Feeder (ADF) retuns only one page on certain scanners

孤街醉人 提交于 2019-11-29 07:29:33

I see you're calling a method called SetupADF, which is not shown, that presumably sets some properties on the device object. Have you tried setting WIA_DPS_PAGES (property 3096) and/or WIA_DPS_SCAN_AHEAD_PAGES (property 3094)?

I have a blog post about scanning from an ADF in Silverlight, and I believe a commenter came up against the same issue you're having. Setting WIA_DPS_PAGES to 1 fixed it for him. I ended up modifying my code's SetDeviceProperties method to set WIA_DPS_PAGES to 1 and WIA_DPS_SCAN_AHEAD_PAGES to 0.

Thomas Elstrøm

After alot of trial and error I stumbled upon a solution which worked for reasons I'm not quite sure of. It seems like the ShowTransfer() method was unable to convert the page to .png or .tiff WHILE scanning. Setting the format to JPEG or BMP actually solved the issue for me:

image = (ImageFile)scanDialog.ShowTransfer(item, wiaFormatJPEG, false);

I think I saw somewhere on the web that this method actually returns BMP regardless of the format specified. Might be that converting the image to png or tiff is too heavy as opposed to using bmp or jpeg.

On a sidenote, I'm setting the property setting: 3088 to 0x005 (adf AND duplex mode).

we had a very similar problem and various solutions, e.g. by setting certain properties, did not help. The main problem was that the scanner (ADF) retracted all pages on startup, regardless of what was happening in the program code. The process repeatedly led to errors, since "too much" was made before the next page was scanned. This applies in particular to the fact that another "Connect" was attempted. For this reason, we have modified the code so that the individual pages can be read in as quickly as possible:

public List<Image> Scan(string deviceID)
    {
        List<Image> images = new List<Image>();

        WIA.ICommonDialog wiaCommonDialog = new WIA.CommonDialog();
        WIA.Device device = this.Connect(deviceID);
        if (device == null)
            return images;

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

        List<WIA.ImageFile> wiaImages = new List<ImageFile>();
        try
        {
            // scan images
            do
            {
                WIA.ImageFile image = (WIA.ImageFile)wiaCommonDialog.ShowTransfer(item, wiaFormatJPEG, false);
                wiaImages.Add(image);
            } while (true);
        }
        catch (System.Runtime.InteropServices.COMException ex)
        {
            if ((uint)ex.ErrorCode != WIA_PROPERTIES.WIA_ERROR_PAPER_EMPTY)
                throw ex;
        }
        catch (Exception ex)
        {
            throw ex;
        }

        foreach (WIA.ImageFile image in wiaImages)
            this.DoImage(images, image);

        return images;
    }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!