I have an HP Scanjet 7000 scanner (duplex and ADF scanner) and an HP Scanjet 5500c (ADF only) and the scanner program I am developing that uses WIA 2.0 in Windows 7.
The problem is that the code works fine on the old scanner model, but in the newer version, the code seems to work fine on the first page, and then goes to the second. If I go through the code around the next line;
image = (WIA.ImageFile)wiaCommonDialog.ShowTransfer(item, wiaFormatTIFF, false);
the old scanner stops and expects that another call will be made via the same link, but the newer one will go through all its pages from the feeder during one continuous operation.
I notice that if I use the default scanning program in Windows 7, the new one returns a .tif file containing all the individual pages. The older one returns separate .jpg files (one for each page).
This indicates that the new scanner scans its entire feeder before it is ready to return a collection of images, where the older one returns an ONE image between each checked page.
How can I support this behavior in code? The following is part of the corresponding code that runs on an older scanner model:
public static List<Image> Scan(string scannerId) { List<Image> images = new List<Image>(); List<String> tmp_imageList = new List<String>(); bool hasMorePages = true; bool useAdf = true; bool duplex = false; int pages = 0; string fileName = null; string fileName_duplex = null; WIA.DeviceManager manager = null; WIA.Device device = null; WIA.DeviceInfo device_infoHolder = null; WIA.Item item = null; WIA.ICommonDialog wiaCommonDialog = null; manager = new WIA.DeviceManager(); // select the correct scanner using the provided scannerId parameter foreach (WIA.DeviceInfo info in manager.DeviceInfos) { if (info.DeviceID == scannerId) { // Find scanner to connect to device_infoHolder = info; break; } } while (hasMorePages) { wiaCommonDialog = new WIA.CommonDialog(); // Connect to scanner device = device_infoHolder.Connect(); if (device.Items[1] != null) { item = device.Items[1] as WIA.Item; try { if ((useAdf) || (duplex)) SetupADF(device, duplex); //Sets the right properties in WIA WIA.ImageFile image = null; WIA.ImageFile image_duplex = null; // scan image image = (WIA.ImageFile)wiaCommonDialog.ShowTransfer(item, wiaFormatTIFF, false); if (duplex) { image_duplex = (ImageFile)wiaCommonDialog.ShowTransfer(item, wiaFormatPNG, false); } // save (front) image to temp file fileName = Path.GetTempFileName(); tmp_imageList.Add(fileName); File.Delete(fileName); image.SaveFile(fileName); image = null; // add file to images list images.Add(Image.FromFile(fileName)); if (duplex) { fileName_duplex = Path.GetTempFileName(); tmp_imageList.Add(fileName_duplex); File.Delete(fileName_duplex); image_duplex.SaveFile(fileName_duplex); image_duplex = null; // add file_duplex to images list images.Add(Image.FromFile(fileName_duplex)); } if (useAdf || duplex) { hasMorePages = HasMorePages(device); //Returns true if the feeder has more pages pages++; } } catch (Exception exc) { throw exc; } finally { wiaCommonDialog = null; manager = null; item = null; device = null; } } } device = null; return images; }
Any help on this would be greatly appreciated! I can not find a working solution on the Internet. Unanswered messages from people with the same problem.
source share