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

Set Default Devices and reset the acquire()

Mar 13, 2014 at 6:02 AM
Hi, i need some help here. how can i set specific devices as my default device and how can i clear the previous preview page when i run acquire() or show the crop size when run acquire().

try
        {
            if (lblTitle.Text == "A4")
            {
               // how can i set the crop size?
                this._twain.SetCap(TwCap.ClearPage, true);   //i want to clear the previous preview 
                this._twain.SelectSource("canoScan 8800F");  //i want to set default devices
                this._twain.Acquire();

            }
            else
            {
                this._twain.Acquire();
            }


        }
        catch (Saraff.Twain.TwainException ex)
        {
            MessageBox.Show(ex.Message, "SAMPLE1", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
My saraff.twain version is 1.0.2.312.
Coordinator
Mar 16, 2014 at 3:56 PM
Edited Mar 16, 2014 at 5:03 PM
Hello, piaking.
For set specific devices as my default device invoke Twain32.SelectSouce() (See Saraff.Twain.Sample1 ("Select DS" button)).
For clear the previous preview page try follow code (See Saraff.Twain.Sample1 AcquireCompleted event handler)
            if(this.pictureBox1.Image!=null) {
                this.pictureBox1.Image.Dispose();
            }
            this.pictureBox1.Image=null; // or fake image
            //...
            this.pictureBox1.Image=this._twain.GetImage(0);
For set crop size see this thread
Apr 3, 2014 at 3:04 AM
Edited Apr 3, 2014 at 7:41 AM
Hi saraff

i dun want to clear pictureBox1.. just the ScanGear image.
i tried to clear the previous preview page inside the ._twain.. but still unable to get it.. is there a way like this work "this.twain.image.clear()"?

this._twain.OpenDSM();
this._twain.OpenDataSource();
this._twain.SetResolutions(150f);
this._twain.Acquire();

the follow code above are working for me for settings the DPI once the acquire is call.
is there a way to set the Output Size settings once the acquire() is call?
once the acquire() is call i want the Output Size to select "L Portrait". Is it possible?

I try using the following code below also can't work please help me check what is the problem

var autoscan = this._twain.GetCap(TwCap.AutoScan); << catch the error here "Capability not supported by source"
this._twain.SetCap(TwCap.AutoScan, autoscan );

i tried this also cannot work " this._twain.SetCap(TwCap.AutoScan, true);"

this "TwRC _rc=this._DsCap(this._appid,this._srcds,TwDG.Control,TwDAT.Capability,TwMSG.Set,_cap);" << always give me failed _rc

sorry for my poor english hope u understand.
Apr 3, 2014 at 3:18 AM
Edited Apr 3, 2014 at 3:21 AM
i tried using this following code but not working for me

try
        {
            this._twain.OpenDSM();
            this._twain.OpenDataSource();
            var _supportedSizesCap = this._twain.IsCapSupported(TwCap.SupportedSizes);

            //#region Get list supported sizes (as sample)

            if ((_supportedSizesCap & TwQC.Get) != 0)
            {
                var _supportedSizes = this._twain.GetCap(TwCap.SupportedSizes) as Twain32.Enumeration;
                var _currentSize = (TwSS)_supportedSizes[_supportedSizes.CurrentIndex];
                for (int i = 0; i < _supportedSizes.Count; i++)
                {
                    System.Diagnostics.Debug.WriteLine((TwSS)_supportedSizes[i]); //show supported sizes
                }
            }

            //#endregion

            if ((_supportedSizesCap & TwQC.Set) != 0)
            {   
                this._twain.SetCap(TwCap.SupportedSizes, (ushort)TwSS.A4); <<< once acquiry() is call A4 nv been selected.
            }

               // PointF point1 = new PointF(10.5F, 10F);
               // SizeF size1 = new SizeF(10.5F, 5.5F);
                this._twain.SetResolutions(150f);
            //    this._twain.SetUnitOfMeasure(TwUnits.Pixels);
               // this._twain.SetPixelType();
                this._twain.Acquire();

        }
        catch (TwainException ex)
        {
            MessageBox.Show(ex.Message, "SAMPLE2", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }


    public enum TwSS : ushort
    {
        None = 0,
        A4Letter = 1,
        B5Letter = 2,
        USLetter = 3,
        USLegal = 4,
        /* Added 1.5 */
        A5 = 5,
        B4 = 6,
        B6 = 7,
        /* Added 1.7 */
        USLedger = 9,
        USExecutive = 10,
        A3 = 11,
        B3 = 12,
        A6 = 13,
        C4 = 14,
        C5 = 15,
        C6 = 16,
        /* Added 1.8 */
        _4A0 = 17,
        _2A0 = 18,
        A0 = 19,
        A1 = 20,
        A2 = 21,
        A4 = A4Letter,
        A7 = 22,
        A8 = 23,
        A9 = 24,
        A10 = 25,
        ISOB0 = 26,
        ISOB1 = 27,
        ISOB2 = 28,
        ISOB3 = B3,
        ISOB4 = B4,
        ISOB5 = 29,
        ISOB6 = B6,
        ISOB7 = 30,
        ISOB8 = 31,
        ISOB9 = 32,
        ISOB10 = 33,
        JISB0 = 34,
        JISB1 = 35,
        JISB2 = 36,
        JISB3 = 37,
        JISB4 = 38,
        JISB5 = B5Letter,
        JISB6 = 39,
        JISB7 = 40,
        JISB8 = 41,
        JISB9 = 42,
        JISB10 = 43,
        C0 = 44,
        C1 = 45,
        C2 = 46,
        C3 = 47,
        C7 = 48,
        C8 = 49,
        C9 = 50,
        C10 = 51,
        USStatement = 52,
        BusinessCard = 53
    }
Coordinator
Apr 3, 2014 at 8:29 PM
Hello, piaking.
Try follow code:
this._twain32.ImageLayout=new RectangleF(3,4,5.5f,5);
Apr 4, 2014 at 1:28 AM
Edited Apr 4, 2014 at 6:13 AM
Hi Saraff

The following code
this._twain32.ImageLayout=new RectangleF(3,4,5.5f,5);
work perfectly fine.

But i want the Output Size select "A4" once i call acquiry() and i can move the crop properly.
Similar as "this._twain.SetPixelType(TwPixelType.Gray);" after i call acquiry() its auto selected "Document(Grayscale)"

Image
[IMG]http://i57.tinypic.com/693py8.png[/IMG]

i thinking of select Output Size is "this._twain.SetUnitOfMeasure(TwUnits.Pixels);" but i dunno how to select the specify option i want.
Coordinator
Apr 4, 2014 at 9:00 AM
Hello, piaking.
I highly encourage you to read the TWAIN Specification. Because You do not fully understand the principles of the TWAIN.
For example, SetUnitOfMeasure(TwUnits.Pixels) sets pixel as the unit of length (thus, specifying ImageLayout = new RectangleF(3,4,5.5f,5) you can determine the size of the frame to scan 5.5 to 5 pixels, the upper left corner is located at coordinates 3;4 pixels). SetUnitOfMeasure(TwUnits.Inches) sets inch as the unit of length (thus, specifying ImageLayout = new RectangleF(3,4,5.5f,5) you can determine the size of the frame to scan 5.5 to 5 inches, the upper left corner is located at coordinates 3;4 inch).
Thus different devices support different units of measurement. Supported units of measure can be obtained using the method GetUnitOfMeasure().
In general, the application must calculate the required size of the frame using the current unit of length and set the value of ImageLayout.
Marked as answer by SARAFF on 6/23/2014 at 12:32 PM