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

Ориентация страницы

Aug 18, 2015 at 8:19 AM
Добрый день!
Не выходит разобраться с тем как задать ориентацию страницы, какой диапазон значений принимает это свойство и какое значение соответствует какой ориентации?
Ниже семпл кода, c DPI и AutoBright все отлично, а вот ориентация:
            //Dpi settings
            if ((twainDriver.IsCapSupported(TwCap.XResolution) & TwQC.Set) == TwQC.Set) {
                twainDriver.Capabilities.XResolution.Reset();
                twainDriver.Capabilities.YResolution.Reset();
                twainDriver.Capabilities.XResolution.Set(Properties.Settings.Default.Resolution);
                twainDriver.Capabilities.YResolution.Set(Properties.Settings.Default.Resolution);
            }
            //Auto-bright settings
            if ((twainDriver.IsCapSupported(TwCap.AutoBright) & TwQC.Set) == TwQC.Set) {
                twainDriver.ResetCap(TwCap.AutoBright);
                twainDriver.SetCap(TwCap.AutoBright, true);
            }
            //Autosize settings
            if ((twainDriver.IsCapSupported(TwCap.SupportedSizes) & TwQC.Set) == TwQC.Set) {
                twainDriver.ResetCap(TwCap.AutoSize);
                twainDriver.SetCap(TwCap.AutoSize, true);
            }
            //Orientation settings
            if ((twainDriver.IsCapSupported(TwCap.Orientation) & TwQC.Set) == TwQC.Set) {
                twainDriver.ResetCap(TwCap.Orientation);
                twainDriver.SetCap(TwCap.Orientation, (UInt16)0);
            }
P.S. Заранее спасибо и отдельная благодарность за прекрасную библиотеку)
Coordinator
Aug 18, 2015 at 7:29 PM
Добрый день, SetSun.
На самом деле все достаточно просто:

ICAP_ORIENTATION

Description

Defines which edge of the “paper” the image’s “top” is aligned with. This information is used to adjust the frames to match the scanning orientation of the paper. For instance, if an ICAP_SUPPORTEDSIZE of TWSS_ISOA4 has been negotiated, and ICAP_ORIENTATION is set to TWOR_LANDSCAPE, then the Source must rotate the frame it downloads to the scanner to reflect the orientation of the paper.
  • ICAP_ORIENTATION affects the values reported by ICAP_FRAMES when using ICAP_SUPPORTEDSIZES.
  • ICAP_ORIENTATION is ignored when set using ICAP_FRAMES or DAT_IMAGELAYOUT.
    The upper-left of the image is defined as the location where both the primary and secondary scans
    originate. (The X axis is the primary scan direction and the Y axis is the secondary scan direction.)
    For a flatbed scanner, the light bar moves in the secondary scan direction. For a handheld scanner,
    the scanner is drug in the secondary scan direction. For a digital camera, the secondary direction
    is the vertical axis when the viewed image is considered upright.

Application

If one pivots the image about its center, then orienting the image in TWOR_LANDSCAPE has the effect of rotating the original image 90 degrees to the “left.” TWOR_PORTRAIT mode does not rotate the image. The image may be oriented along any of the four axes located 90 degrees from the unrotated image. Note that:
TWOR_ROT0 == TWOR_PORTRAIT and TWOR_ROT270 == TWOR_LANDSCAPE.

Values

Type: TW_UINT16
Default Value: TWOR_PORTRAIT
Allowed Values:
  • TWOR_ROT0
  • TWOR_ROT90
  • TWOR_ROT180
  • TWOR_ROT270
  • TWOR_PORTRAIT (equals TWOR_ROT0)
  • TWOR_LANDSCAPE (equals TWOR_ROT270)

Containers

MSG_GET: TW_ONEVALUE, TW_ENUMERATION
MSG_GETCURRENT: TW_ONEVALUE
MSG_GETDEFAULT: TW_ONEVALUE
MSG_SET: TW_ONEVALUE
MSG_SETCONSTRAINT: TW_ONEVALUE, TW_ENUMERATION
MSG_RESET: TW_ONEVALUE
MSG_QUERYSUPPORT: TW_ONEVALUE

TWAIN 2.2 Specification 10-167

В общем, читайте TWAIN Specification и мат.часть.
Следующий пример, должен помочь Вам разобраться.
if((this._twain32.Capabilities.Orientation.IsSupported()&(TwQC.Get|TwQC.Set))==(TwQC.Get|TwQC.Set)) {
    var _supportedValues=this._twain32.Capabilities.Orientation.Get();
    System.Diagnostics.Debug.WriteLine("ICAP_ORIENTATION supported values:");
    for(var i=0; i<_supportedValues.Count; i++) {
        System.Diagnostics.Debug.WriteLine(_supportedValues[i]);
    }

    try {
        this._twain32.Capabilities.Orientation.Set(TwOR.Rot90);
    } catch(TwainException ex) {
        if(ex.ConditionCode==TwCC.BadValue) {
            // value is not supported.
        }
    }
}
Marked as answer by SARAFF on 8/24/2015 at 7:56 AM