Image acquiring

Questions, comments and suggestions concerning VintaSoft Twain .NET SDK.

Moderator: Alex

Post Reply
malovern
Posts: 4
Joined: Tue Aug 06, 2013 6:14 pm

Image acquiring

Post by malovern » Tue Nov 04, 2014 8:40 pm

Hi,

I am running into a problem scanning duplex images where occasionally, the images are being saved with one page of one image and one of another scanned image (these are scanned on a Canon dr6010c in batches)

My ImageAcquired code is below with the barcode processing in a separate thread. My question is, when duplex is enabled, are images always sent in the exact order they are scanned?

This is a head scratcher for me

Any help appreciated,

Kind Regards

Jim

Code: Select all

private void onDevice_ImageAcquired(object sender, ImageAcquiredEventArgs e)
{
    try
    {
        Device _device = (Device)sender;

        // image acquisition must be cancelled because application's form is closing
        if (cancelTransferBecauseFormIsClosing)
        {
            // cancel image acquisition
            _device.CancelTransfer();
            return;
        }

        pageCount++;
        if (imageFileName == string.Empty)
        {
            imageFileName = generateNewFilename();
        }

        AcquiredImage acquiredImage = _device.AcquiredImage;

        if (_device.DocumentFeeder.DuplexEnabled)
        {
            if (!imageFileName.Contains("Y"))
            {
                imageFileName += "Y.tif";
            }
            acquiredImage.Save(
               Path.Combine(currentScanStation.ScanFolder,
               imageFileName));

            //If the page count is 2 then the next image (if any) will be a new file to save
            if (pageCount == 2)
            {
                imageFileName = string.Empty;
                pageCount = 0;
                currentStationScannedCount++;
            }
        }
        else //Not a duplex scan
        {
            imageFileName += "N.tif";
            acquiredImage.Save(
               Path.Combine(currentScanStation.ScanFolder,
               imageFileName));
            imageFileName = string.Empty;
            pageCount = 0;
            currentStationScannedCount++;
        }  
    }
    catch (Exception ex)
    {
        MessageBox.Show("Failed to save image : " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }

    finally
    {
        updateDGVStations(currentScanStation, 1, currentStationScannedCount);
        Application.DoEvents();
    }
}

Alex
Site Admin
Posts: 1544
Joined: Thu Jul 10, 2008 2:21 pm

Re: Image acquiring

Post by Alex » Wed Nov 05, 2014 11:27 am

Hi Jim,

Your code looks correct. I think your scanner can discard blank pages and your application does not receive blank pages. Am I right?

Best regards, Alexander

malovern
Posts: 4
Joined: Tue Aug 06, 2013 6:14 pm

Re: Image acquiring

Post by malovern » Wed Nov 05, 2014 1:33 pm

Hi Alex,

Currently, the application does receive blank pages - testing here on my dr 4010c - I believe its the same behaviour on the 6010c. So I receive two pages per scan regardless of whether one side is blank when duplex is enabled.

I am wondering if the processing thread is trying to process the images before the image is properly saved. To this end, I have made some changes to scan the images into another folder then move them into a processing folder. This way, this ensures the files are written correctly prior to being checked for barcodes. I have also added code to set the acquiredImage class to disposed after each scan to ensure that the image being saved is the current one, hopefully this resolves it ;)

From my limited testing, it does appear that the scanner (and thus Vintasoft) does send the images in the order they are scanned.

Kind Regards

Jim

Alex
Site Admin
Posts: 1544
Joined: Thu Jul 10, 2008 2:21 pm

Re: Image acquiring

Post by Alex » Thu Nov 06, 2014 12:33 pm

Hi Jim,
I am wondering if the processing thread is trying to process the images before the image is properly saved.
Your application processes acquired image in background thread. Am I right? If yes, you need examine your code for logical mistake.

Please let me know if you will have any question or problem.

Best regards, Alexander

Post Reply