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

Scanning another page.

Nov 18, 2014 at 4:56 PM
Edited Nov 18, 2014 at 6:58 PM
Sometimes the initial call to this._twain32.Acquire (), seems to do nothing. It does show the dialog, but freezes after pressing the dialogs scan button. Is there a fix for this? Very often than not, once I call this._twain32.Acquire (), i get the scanner dialog, but it does not scan. It simply freezes.

Is there a way to hide the scanner's UI all together, and just have it scan and return the image?
 private void _AcquireCompleted(object sender, EventArgs e) {
            try {

                if(this._twain32.ImageCount>0) {
                    var _stream=new MemoryStream();
                    this._twain32.GetImage(0).Save(_stream, ImageFormat.Bmp);
                    Image temporaty = this._twain32.GetImage(0);

                    Bitmap temp = (Bitmap)temporaty.Clone();

                    MemoryStream ms = new MemoryStream();
                    temp.Save(ms, ImageFormat.Png);
                    ms.Position = 0;

                    ImageStreamList.Add(ms);
 

                   // this.image1.Source=_img;
                }
            } catch(Exception ex) {
                //MessageBox.Show(ex.Message, ex.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void selectButton_Click() {
            try {
                this._twain32.CloseDataSource();
                this._twain32.SelectSource();

            } catch(Exception ex) {
                //MessageBox.Show(ex.Message, ex.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }


        private void scanButton_Click() {
            try {
                this._twain32.Acquire();
            } catch(Exception ex) {
                //MessageBox.Show(ex.Message, ex.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Error);
            }
Coordinator
Nov 18, 2014 at 7:40 PM
Hello, LastKings!
See documentation of Saraff.Twain.NET. Also, try Saraff.Twain.Sample2.
Marked as answer by SARAFF on 12/4/2014 at 2:07 AM
Nov 19, 2014 at 3:23 PM
Edited Nov 19, 2014 at 3:39 PM
When calling this._twain32.Acquire (), the program seems to get caught in a message loop, and fails to continue the scanning process.
It enters the application.MessageLoop statement, and never returns from it...

I use a while loop to continue to call the Acquire command until it scans at least one image. Then it continues.
However, this results in acquire being called endlessly without the scanner activating.
Is there a reset that needs to be called after calling Acquire, if you are trying to scan until at least one image has been scanned?

Also, it seems that once the Acquire freezes, it continues to create threads that exit with code 259 (0x103).

Can you assists me with this problem?
                                if(!this.IsTwain2Supported||(this._srcds.SupportedGroups&TwDG.DS2)==0) {
                                    this._filter.SetFilter();
                                }
                                if(!Application.MessageLoop) {
                                    Application.Run(this._context=new ApplicationContext());
                                }
                                break;
Coordinator
Nov 19, 2014 at 4:46 PM
Hello, LastKings!
I suspect that the problem is with the scanner (the data source). Have you tried to use another program to scan (for example, Saraff.Twain.Sample1 or Saraff.Twain.Sample2)?
Nov 19, 2014 at 4:53 PM
Yes, using Saraff.Twain.Sample1 or Saraff.Twain.Sample2 seems to work fine, but when using the exact same method to print in my own code, it still freezes quite often.

What do you mean by data source?
Coordinator
Nov 19, 2014 at 5:21 PM