Set ICapOrientation

Issue #20 resolved
Ferdinando Santacroce created an issue

Good evening Eugene.

I have to set a default orientation for the acquired image to 0 degrees. I'm trying to figure out how to do this job, setting CapabilityId.ICapOrientation: is this right? Can you post me an example about creating and setting a TWCapability() of this kind?

Thank you. Nando

Comments (7)

  1. Eugene Wang repo owner

    Use this typical format for reading/setting simple cap types that I haven't defined with a CapWrapper yet.

    // get allowed values
    IList<OrientationType> supportedOrientations = session.CurrentSource.CapGet(CapabilityId.ICapOrientation).CastToEnum<OrientationType>();
    
    // get current value
    OrientationType curOrientation = session.CurrentSource.CapGetCurrent(CapabilityId.ICapOrientation).ConvertToEnum<OrientationType>();
    
    // set new value, must be one of the allowed values.
    // also see twain spec for the type and value to use with ICapOrientation
    OrientationType newOrientation = OrientationType.Landscape;
    using (var cap = new TWCapability(CapabilityId.ICapOrientation, new TWOneValue
                    {
                        Item = (uint)newOrientation,
                        ItemType = ItemType.UInt16 
                    }))
    {
    
        this.CurrentSource.DGControl.Capability.Set(cap);
    }
    
  2. Ferdinando Santacroce reporter

    I found a ResetAll() method, but I don't know how to use it. It seems you can use it to reset a capability to his default, but in my trials I verified it resets not only that capability, but many others. In brief: I don't understand if it is to reset a capability or all capabilites. Can you help me?

    Thank you, Nando

  3. Eugene Wang repo owner

    ResetAll() changes all cap values to the driver's power-on defaults (I think my ResetAll has the wrong parameter). If you need to reset a single cap use Reset(). Resets do not appear to allow you to change the power-on default value. Only the driver gets to decide what it will be, whether it may decide to use the value that was Set() from the previous scan session or not (most drivers don't).

  4. Ferdinando Santacroce reporter

    Thank you Eugene, you are very kind.

    I will try to explain it better: I have to load some settings from .ini file, resetting the rotation of the image acquired to 0 degrees. Consider an .ini where a customer sets 90 degrees rotation for the acquired image: I have to programmatically set the value to 0 to get my work done.

    I have tried to follow your suggestions; here the results:
    1) Resetting a capability
    var twCapability = new TWCapability(CapabilityId.ICapOrientation);
    var returnCode = twainSession.CurrentSource.DGControl.Capability.Reset(twCapability);
    It seems to work correctly, but my image is again at 90 degrees rotated.

    2) Setting a capability to 0
    Using your code the set seems to work (I set it to OrientationType.Rot0), but my image is again at 90 degrees rotated.

    Maybe that is not hte right capability to set?
    In ISIS layer that is the advanced tag number 275, but in TWAIN I don't know.
    Using ISIS and reading an *.ini file written after the rotation set I realized that it sets DataOrientation=0 (I've got a Canon DR9080C for my lab tests), so I think I have to catch how TWAIN calls that filed to finally get a working solution.

    Do you have some other suggestions?

    Thank you!
    Nando

  5. Eugene Wang repo owner

    Rot0 is just the default and since it doesn't behave correctly then you could try Rot90 or Rot270, depending how the page is loaded in the tray.

    i.e. what you think is 0 may not be 0 from the scanner's point of view.

  6. Log in to comment