adf scanning using WIA ... only one image saved!!!

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Greetings my problem with adf scanning is that the transfer method (the underlined & bold) in the code is taking all the papers in the scanner at one time with wont make the rest of checks after this statement running correctly as i want . this statement
also takes only one page and ignore the others, please check my code and tell me if is there any thing to do.

<pre class="prettyprint class Scanner
{
private readonly DeviceInfo _deviceInfo;

public Scanner(DeviceInfo deviceInfo)
{
this._deviceInfo = deviceInfo;
}
public override string ToString()
{
return this._deviceInfo.Properties["Name"].get_Value();
}

Image[] Img_aft = new Image[9999];

public int Scan(int numPages,int id,string name)
{

bool hasMorePages = true;
int begin = numPages;
int x = 0;
var device = this._deviceInfo.Connect();
const string wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}";
var item = device.Items[1];
ImageFile [] imageFile = new ImageFile[9999];
while (hasMorePages)
{
try
{
imageFile[numPages] = (ImageFile)item.Transfer(wiaFormatJPEG);
item = null;
Property documentHandlingSelect = null;
Property documentHandlingStatus = null;
foreach (Property prop in device.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;
if (documentHandlingSelect != null)
{

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);
}
}




var path = "d:\archive\" + DateTime.Now.ToString().Replace(/, -).Replace(:, -).Substring(0, 19) + "" + numPages + ".jpeg";
if (File.Exists(path))
{
File.Delete(path);
}
imageFile[numPages].SaveFile(path);
Img_aft[numPages] = Image.FromFile(path);
MemoryStream ms = new MemoryStream();
Img_aft[numPages].Save(ms, ImageFormat.Jpeg);
Byte[] bytBLOBData = new Byte[ms.Length];
ms.Position = 0;
ms.Read(bytBLOBData, 0, Convert.ToInt32(ms.Length));
new DB().ApplyNonQuery("insert into [File] ([file_name] ,[file] ,[item_id])values(" + name + "" + numPages + ",@image," + id + ")", bytBLOBData, "@image");


x++;
numPages++;
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}



return x;
}
}

class WIA_DPS_DOCUMENT_HANDLING_SELECT
{
public const uint FEEDER = 0x00000001;
public const uint FLATBED = 0x00000002;
}

class WIA_DPS_DOCUMENT_HANDLING_STATUS
{
public const uint FEED_READY = 0x00000001;
}

class WIA_PROPERTIES
{
public const uint WIA_RESERVED_FOR_NEW_PROPS = 1024;
public const uint WIA_DIP_FIRST = 2;
public const uint WIA_DPA_FIRST = WIA_DIP_FIRST + WIA_RESERVED_FOR_NEW_PROPS;
public const uint WIA_DPC_FIRST = WIA_DPA_FIRST + WIA_RESERVED_FOR_NEW_PROPS;

public const uint WIA_DPS_FIRST = WIA_DPC_FIRST + WIA_RESERVED_FOR_NEW_PROPS;
public const uint WIA_DPS_DOCUMENT_HANDLING_STATUS = WIA_DPS_FIRST + 13;
public const uint WIA_DPS_DOCUMENT_HANDLING_SELECT = WIA_DPS_FIRST + 14;
}

class WIA_ERRORS
{
public const uint BASE_VAL_WIA_ERROR = 0x80210000;
public const uint WIA_ERROR_PAPER_EMPTY = BASE_VAL_WIA_ERROR + 3;
}[/code]
<br/>

<
zigzago
<br/>
<br/>
<br/>

View the full article
 
Back
Top