I finally figured out what I was doing wrong and now it is saving multiple pages properly. Every one and awhile though, the user gets a divide by zero error, they exit the program, log back in and it works fine. Later just out of the blue, after working for a while it happens again. Here is the code.
if (vsTwain1.FeederLoaded)
{
vsTwain1.ShowIndicators = true;
while (vsTwain1.AcquireModal())
{
try
{
pictureBox1.Image = vsTwain1.GetCurrentImage();
vsTwain1.SaveImage(0, dirPath + filePath);
}
catch (TwainException ex)
{
if (vsTwain1.ErrorCode != Vintasoft.Twain.ErrorCode.None)
MessageBox.Show(vsTwain1.ErrorString);
else
MessageBox.Show(ex.Message);
}
}
myController.SaveScannedRecord(Int32.Parse(rdType.ToString()), filePath, DescriptionTextBox.Text.ToString(), numOfPages);
vsTwain1.StopDevice();
MessageBox.Show("Scan completed.");
}
Divide by zero error
Moderator: Alex
Re: Divide by zero error
Hello Bill,
First of all you must dispose the image in the PictureBox when you replace it.
Here is correct code:
Could you tell me in which line of code the "divide by zero" error occurs?
Best regards, Alexander
First of all you must dispose the image in the PictureBox when you replace it.
Here is correct code:
Code: Select all
if (vsTwain1.FeederLoaded)
{
vsTwain1.ShowIndicators = true;
while (vsTwain1.AcquireModal())
{
try
{
if (pictureBox1.Image != null)
{
pictureBox1.Image.Dispose();
pictureBox1.Image = null;
}
pictureBox1.Image = vsTwain1.GetCurrentImage();
vsTwain1.SaveImage(0, dirPath + filePath);
}
catch (TwainException ex)
{
if (vsTwain1.ErrorCode != Vintasoft.Twain.ErrorCode.None)
MessageBox.Show(vsTwain1.ErrorString);
else
MessageBox.Show(ex.Message);
}
}
myController.SaveScannedRecord(Int32.Parse(rdType.ToString()), filePath, DescriptionTextBox.Text.ToString(), numOfPages);
vsTwain1.StopDevice();
MessageBox.Show("Scan completed.");
}
Best regards, Alexander
Re: Divide by zero error
That solved the problem of the divide by zero error. When the user scans a one page document everyone works fine, but when the user scans a document with two pages it actually scans the first page multiple times into the file. I can't duplicate this on my system. Tthey and I are using a HP Scanjet N6010 and using the WIA drivers.
Bill
Bill
Re: Divide by zero error
Hello Bill,
Please try to download and use version 2.0 driver for HP N6010 scanner from this link:
http://driverscollection.com/?H=ScanJet%20N6010&By=HP
and let me know results.
Best regards, Alexander
Please try to download and use version 2.0 driver for HP N6010 scanner from this link:
http://driverscollection.com/?H=ScanJet%20N6010&By=HP
and let me know results.
Best regards, Alexander