C#: How to avoid WIA-error when scanning documents with 2400dpi or more?

1

when we scan a document with a resolution of 2400dpi or higher, we recieve (for example) the following error-message:

COMException: Ausnahme von HRESULT: 0x80010100 (RPC_E_SYS_CALL_FAILED)

or

COMException: Ausnahme von HRESULT: 0x8021006F

in one of the following lines

            img = itm.Transfer(scanFormat.ScanFormat) as WIA.ImageFile;
            img = ip.Apply(img as WIA.ImageFile);

some screenshots for the mentioned errors:

http://www.amarant-it.de/TempDownload/WIA_Error01.png

or the same path with WIA_Error02.png and WIA_Error03.png

for scanning we use the following code:

            #region Image-Convert-Settings
            //IP.Filters.Add IP.FilterInfos("Convert").FilterID
            //IP.Filters(1).Properties("FormatID").Value = wiaFormatJPEG
            WIA.IImageProcess ip = new WIA.ImageProcessClass();
            object convert = "Convert";
            WIA.IFilterInfo fi = ip.FilterInfos.get_Item(ref convert);
            ip.Filters.Add(fi.FilterID, 0);
            convert = "FormatID";
            object formatstring = scanFormat.ScanFormat;
            WIA.IFilter filter;
            foreach (WIA.IFilter fTemp in ip.Filters)
            {
                filter = fTemp;
                WIA.IProperty prop = filter.Properties.get_Item(ref convert);
                prop.set_Value(ref formatstring);
            }
            #endregion
            #region Image-Scan + Convert
            img = itm.Transfer(scanFormat.ScanFormat) as WIA.ImageFile;
            img = ip.Apply(img as WIA.ImageFile);
            img.SaveFile("D:\\scan2." + img.FileExtension);
            Image image = Image.FromFile("D:\\scan2." + img.FileExtension);
            ilImages.Images.Add(image.ToString(), image);
            alImages.Add(image);
            if (ImageScanned != null)
            {
                ImageScanned(image);
            }
            #endregion

can anyone help us with this problem?

thanks

c#
.net
wia
image-scanner
asked on Stack Overflow May 5, 2010 by Stephan_W • edited May 15, 2011 by skaffman

1 Answer

0

I'm going to guess you're doing A4/8.5x11 in color (32-bit) - that's very close to 2 gig for a BMP, which is close to the limit of a 32-bit signed number. I'd say it's not so much resolution but total data size. At least limits of the COM data structures is the conclusion of this author of a silverlight scan application. If you think about it, if it ever all shows up in a buffer for a 32-bit process, you'll run out of memory trying to allocate a contiguous chunk of memory that big.

My WIA knowledge has faded a bit, but if I recall correctly, WIA scans via a service, if it's 32-bit and you're calling it via COM, that's where the buffer and the limit comes from. That and if you don't get the scan parameters just right, it'll pick BMP (no compression). I can't seem to recall if you can get it to do JPEG for color or if you're forced to go through a converter. If you want to work with data that's this big, one option could be is to switch to the C++ api, which allows streamed instead of buffered access (I've never used it but I mentioned it in case it helps).

answered on Stack Overflow May 15, 2011 by Tony Lee

User contributions licensed under CC BY-SA 3.0