This project has moved. For the latest updates, please go here.

Detect Front Rear Page when acquiring in Duplex mode

Oct 6, 2014 at 2:52 PM
Hi,
I'm using this very good component to acquire from a document scanner that supports duplex acquisition (Kodak I1220)
I use the EndXfer event to retrieve Image when scanning is still going.
I wasn't able to find a way to discriminate between two consecutive sheet acquisition and two sides of the same sheet.
Could you please help me?
Thanks a lot for the support and the excellent component.
Coordinator
Oct 6, 2014 at 4:17 PM
Hello, GLR_73!
Thank you for your opinion about my project.

Try follow code:
if((this._twain32.IsCapSupported(TwCap.Duplex)&TwQC.GetCurrent)!=0) {
    if((TwDX)this._twain32.GetCurrentCap(TwCap.Duplex)==TwDX.TwoPassDuplex) {
        if((this._twain32.IsCapSupported(TwCap.DuplexEnabled)&TwQC.GetCurrent)!=0) {
            if((bool)this._twain32.GetCurrentCap(TwCap.DuplexEnabled)) {
                // <<< two sides of the same sheet
                // odd numbers - fore side
                // even numbers - back side
            }
        }
    }
}

// ...
internal enum TwDX:ushort {
    None=0,          // TWDX_NONE
    OnePassDuplex=1, // TWDX_1PASSDUPLEX
    TwoPassDuplex=2  // TWDX_2PASSDUPLEX
}
Oct 6, 2014 at 6:39 PM
Hello Saraff,
thank You for the answer, actually my scanner supports single pass duplex, so I modified a little the code as follows,
works but still I don't know what variable I must check for Even / odd every time the event is fired.


void _twain32_EndXfer(object sender, Twain32.EndXferEventArgs e)
    {
        try
        {
            if (e.Image != null)
            {
                if ((this._twain32.IsCapSupported(TwCap.Duplex) & TwQC.GetCurrent) != 0)
                {
                    if ((TwDX)this._twain32.GetCurrentCap(TwCap.Duplex) == TwDX.OnePassDuplex)
                    {
                        if ((this._twain32.IsCapSupported(TwCap.DuplexEnabled) & TwQC.GetCurrent) != 0)
                        {
                            if ((bool)this._twain32.GetCurrentCap(TwCap.DuplexEnabled))
                            {
                                // <<< two sides of the same sheet
                                // odd numbers - fore side
                                // even numbers - back side
                                var _stream = new MemoryStream();
                                e.Image.Save(_stream, ImageFormat.Tiff);
                                var _img = new BitmapImage { CacheOption = BitmapCacheOption.OnLoad };
                                _img.BeginInit();
                                _img.StreamSource = _stream;
                                _img.EndInit();
                                this.image1.Source = _img;
                            }
                        }
                    }
                }


            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, ex.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Error);
        }
    }
Coordinator
Oct 6, 2014 at 6:54 PM
Hello, GLR_73!
variable - the number of pages scanned. (if you want to distinguish between the front and back side of the page)
Oct 6, 2014 at 7:06 PM
Hello Saraff,
I don't understand, so I try to explain the problem in more precise way:
My scanner does a single pass scan in duplex mode, and the event is fired once if the sheet is single sided
(it is a feature of the driver that discriminate blank page by a content threshold), and twice if the sheet is double sided.
So let us suppose that I scan a bulk of 20 documents some single faced, and other double faced.
How can I rely on a counter to detect front and rear?
Thanks a lot for the help.
Oct 6, 2014 at 9:49 PM
Hello again,
digging in Twain specification I found:

TWEI_CAMERA and TWEI_PAGESIDE in the ExtImageInfo.
I did some tests implementing _twain32.XferDone
and I found a meaningful value inside the TWEI_CAMERA item (a string reporting "front camera" or "back camera")
But no trace of TWEI_PAGESIDE inside the ExtImageInfo... any clue?

Thanks again
Coordinator
Oct 7, 2014 at 4:42 AM
Hello, GLR_73!
Try follow code:
private void _twain32_XferDone(object sender,Twain32.XferDoneEventArgs e) {
    // ...
    var _extImageInfo=e.GetExtImageInfo(new TwEI[] { TwEI.Camera,TwEI.PageSide });
    foreach(var _item in _extImageInfo) {
        switch(_item.InfoId) {
            case TwEI.Camera:
                // ...
                break;
            case TwEI.PageSide:
                if(_item.IsSuccess) {
                    var _pageSideValue=(TwCS)_item.Value;
                    // ...
                }
                break;
        }
    }
    // ...
}

// ...
internal enum TwCS:ushort {
    Both=0,
    Top=1,
    Bottom=2
}
Marked as answer by GLR_73 on 10/7/2014 at 5:09 AM
Oct 7, 2014 at 12:09 PM
Hello Saraff,
THe TwEI.PageSide entry returned by GetExtImageInfo shows is not supported on my scanner.
Thanks for the support, I will implement the discriminator based on the Camera item.
Your software rocks!