This project has moved and is read-only. For the latest updates, please go here.

HELP ,RE-SCAN IMAGE?

Jun 28, 2013 at 10:19 PM
Hello, I'm Ulises From Mexico!

I'm using the library, and get the scanned image and put into a pictore box, but when I try to go back to get another image in the event of my button the scanner not response. They could spend a simple example of how to do this,please?


Thank you

P. D. excellent dll and sorry for my English
Jun 29, 2013 at 6:40 AM
Hello Ulises.

Follow code show how to do
namespace Saraff.Twain.Sample1 {

    public partial class Form1:Form {

        public Form1() {
            InitializeComponent();
            this._twain.OpenDSM();
        }

        private void button2_Click(object sender,EventArgs e) {
            this._twain.CloseDataSource();
            this._twain.SelectSource();
        }

        private void button1_Click(object sender,EventArgs e) {
            try {
                this._twain.Acquire();
            } catch(TwainException ex) {
                MessageBox.Show(ex.Message,"SAMPLE1",MessageBoxButtons.OK,MessageBoxIcon.Error);
            }
        }

        private void _twain_AcquireCompleted(object sender,EventArgs e) {
            if(this.pictureBox1.Image!=null) {
                this.pictureBox1.Image.Dispose(); //dispose old image
            }
            this.pictureBox1.Image=this._twain.GetImage(0);
        }
    }

    partial class Form1 {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components=null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing) {
            if(disposing&&(components!=null)) {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent() {
            this.components=new System.ComponentModel.Container();
            this._twain=new Saraff.Twain.Twain32(this.components);
            this.pictureBox1=new System.Windows.Forms.PictureBox();
            this.button1=new System.Windows.Forms.Button();
            this.button2=new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            this.SuspendLayout();
            // 
            // _twain
            // 
            this._twain.AppProductName="Saraff.Twain, Version=1.0.0.0";
            this._twain.Parent=this;
            this._twain.AcquireCompleted+=new System.EventHandler(this._twain_AcquireCompleted);
            // 
            // pictureBox1
            // 
            this.pictureBox1.Anchor=((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top|System.Windows.Forms.AnchorStyles.Bottom)
                        |System.Windows.Forms.AnchorStyles.Left)
                        |System.Windows.Forms.AnchorStyles.Right)));
            this.pictureBox1.Location=new System.Drawing.Point(12,12);
            this.pictureBox1.Name="pictureBox1";
            this.pictureBox1.Size=new System.Drawing.Size(268,220);
            this.pictureBox1.SizeMode=System.Windows.Forms.PictureBoxSizeMode.Zoom;
            this.pictureBox1.TabIndex=0;
            this.pictureBox1.TabStop=false;
            // 
            // button1
            // 
            this.button1.Anchor=((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom|System.Windows.Forms.AnchorStyles.Right)));
            this.button1.Location=new System.Drawing.Point(205,238);
            this.button1.Name="button1";
            this.button1.Size=new System.Drawing.Size(75,23);
            this.button1.TabIndex=1;
            this.button1.Text="Scan";
            this.button1.UseVisualStyleBackColor=true;
            this.button1.Click+=new System.EventHandler(this.button1_Click);
            // 
            // button2
            // 
            this.button2.Anchor=((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom|System.Windows.Forms.AnchorStyles.Right)));
            this.button2.Location=new System.Drawing.Point(124,238);
            this.button2.Name="button2";
            this.button2.Size=new System.Drawing.Size(75,23);
            this.button2.TabIndex=2;
            this.button2.Text="Select DS";
            this.button2.UseVisualStyleBackColor=true;
            this.button2.Click+=new System.EventHandler(this.button2_Click);
            // 
            // Form1
            // 
            this.AcceptButton=this.button1;
            this.AutoScaleDimensions=new System.Drawing.SizeF(6F,13F);
            this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize=new System.Drawing.Size(292,273);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.pictureBox1);
            this.Name="Form1";
            this.Text="Form1";
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private Saraff.Twain.Twain32 _twain;
        private System.Windows.Forms.PictureBox pictureBox1;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Button button2;
    }

}
Marked as answer by SARAFF on 6/23/2014 at 12:47 PM