C # WIA with ADF retunes only one page on specific scanners

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.

+5
source share
4 answers

After many trial and error, I came across a solution that worked for reasons that I’m not entirely sure about. It appears that the ShowTransfer () method could not convert the page to a .png or .tiff WHILE scan. Setting the JPEG or BMP format actually solved the problem for me:

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

I think somewhere on the Internet I saw that this method actually returns BMP regardless of the format specified. Converting an image to png or tiff is probably too difficult, unlike using bmp or jpeg.

In the browser, I set the property parameter: 3088 - 0x005 (adf AND duplex mode).

0
source

I see that you are calling a method called SetupADF, which is not shown, which presumably sets some properties of 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 the ADF to Silverlight, and I believe that the commentator was faced with the same problem you are facing, Setting WIA_DPS_PAGES to 1 fixed it for him. I ended up modifying my SetDeviceProperties method of the code to set WIA_DPS_PAGES to 1 and WIA_DPS_SCAN_AHEAD_PAGES to 0.

0
source

we had a very similar problem, and various solutions, for example, by setting certain properties, did not help. The main problem was that the scanner (ADF) cleared all pages at startup, regardless of what happened in the program code. This process has repeatedly led to errors because "too much" was done before scanning the next page. This relates, in particular, to the fact that an attempt was made to another “connection”. For this reason, we changed the code so that individual pages can be read 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; } 
0
source

Can I separate the buttons on the feeder and tablet? when the feeder finishes scanning from the tablet and I get another white page. I can stop the process when there are no pages on the feeder .;

public void ADFScan ()

  { WIA.CommonDialog WiaCommonDialog = new CommonDialogClass(); bool hasMorePages = true; int x = 1; int numPages = 0; while (hasMorePages) { //Create DeviceManager DeviceManager manager = new DeviceManagerClass(); Device WiaDev = null; foreach (DeviceInfo info in manager.DeviceInfos) { if (info.DeviceID == this.DeviceID) { WIA.Properties infoprop = null; infoprop = info.Properties; //connect to scanner WiaDev = info.Connect(); break; } } //Start Scan WIA.ImageFile img = null; WIA.Item Item = WiaDev.Items[1] as WIA.Item; try { img = (ImageFile)WiaCommonDialog.ShowTransfer(Item, FormatID.wiaFormatJPEG, false); //process image: //one would do image processing here // //Save to file string varImageFileName = "C:\\tmp\\" + x.ToString() + ".jpg"; if (File.Exists(varImageFileName)) { //file exists, delete it File.Delete(varImageFileName); } img.SaveFile(varImageFileName); numPages++; img = null; } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } finally { Item = null; //determine if there are any more pages waiting Property documentHandlingSelect = null; Property documentHandlingStatus = null; foreach (Property prop in WiaDev.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; //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); } } x++; } 

}

0
source

All Articles