Page 1 of 1

WPF Viewer Previewing whilst capturing images using TWAIN

Posted: Thu Jun 18, 2015 11:24 am
by pjbnet
Hi,

This maybe in the wrong section but it is to do with Twain and the WPF viewer.

I am moving from the older winforms viewer in V10 to the new WPF viewer in V11. I use code very similar to the winforms sample application for TWAIN capture.

What I am seeing is that if I try to preview the image after TwainAcquireToGdPictureImage the image doesn't show and something in TWAIN gets corrupt and the application loops continously without getting any more images.

Has anyone else come across this?

Here is some code if it helps

Code: Select all

protected GdPicture11.WPF.GdViewer _viewer = new GdPicture11.WPF.GdViewer();

                do
                {
                    if (_pictureImaging.TwainOpenDefaultSource(_windowHandle))
                    {
                        InitScanConfig();

                        Func<bool> doScanning = () =>
                        {
                            bool notBroken = true;
                            do
                            {
                                _viewer.ReleaseGdPictureImage(_currentImage);
                                _currentImage = _pictureImaging.TwainAcquireToGdPictureImage(_windowHandle);
                                if (_currentImage != 0)
                                {
                                    ApplyImageFilters();

// THIS IS THE PROBLEM AREA

                                    if (AppSettingsViewModel.Instance.PreviewImage)
                                    {                                                           
                                        _viewer.DisplayFromGdPictureImage(_currentImage);
                                    }

//END PROBLEM AREA
                                    imageCount++;
                                    string filenum = scanningFolder + string.Format("{0:D9}", imageCount);

                                    switch (imt)
                                    {
                                        case ImageTypes.JPG:
                                            filenum += ".jpg";
                                            break;
                                        case ImageTypes.PDF:
                                            filenum += ".pdf";
                                            break;
                                        case ImageTypes.TIF:
                                            filenum += ".tif";
                                            break;
                                    }

                                    if (File.Exists(filenum))
                                    {
                                        if (MessageBox.Show(@"File already exists click OK to overwrite or cancel to stop scanning", @"Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)
                                        {
                                            notBroken = false;
                                            break;
                                        }
                                    }

                                    switch (imt)
                                    {
                                        case ImageTypes.JPG:
                                            _pictureImaging.SaveAsJPEG(_currentImage, filenum, AppSettingsViewModel.Instance.JPGQuality);
                                            break;
                                        case ImageTypes.PDF:
                                            _pictureImaging.SaveAsPDF(_currentImage, filenum, false, "", "", "", "", "");
                                            break;
                                        case ImageTypes.TIF:
                                            if (tiffCompression == TiffCompression.TiffCompressionCCITT3 || tiffCompression == TiffCompression.TiffCompressionCCITT4)
                                                _pictureImaging.ConvertTo1Bpp(_currentImage);

                                            _pictureImaging.SaveAsTIFF(_currentImage, filenum, tiffCompression);
                                            break;
                                    }

                                    var dvm = new DocumentViewModel(filenum);
                                    var fi = new FileInfo(filenum);
                                    dvm.CreationDate = fi.CreationTime;
                                    dvm.Filesize = (ulong)fi.Length;
                                    _scannedImages.Add(dvm);
                                    _pictureImaging.ReleaseGdPictureImage(_currentImage);
                                }
                                else
                                {
                                    notBroken = false;
                                    break;
                                }
                            }
                            while (Convert.ToInt64(_pictureImaging.TwainGetState()) > Convert.ToInt64(TwainStatus.TWAIN_SOURCE_ENABLED));
                            return notBroken;
                        };


In-process viewing while scanning

Posted: Mon May 23, 2016 2:17 pm
by AH15
Hello,

Is the in-process viewing supported during scan? Can the user review the available scanned images while other images are being scanned? or he needs to wait until all the pages are done?

E.G.: If i have a multi page document (100 pages), can i start viewing the scanned images 1st page,2nd page,3rd page,4th page,etc... or i need to wait until all the images (total 100) have been scanned and acquired by the scanner?

Thank you,
AH15

Re: In-process viewing while scanning

Posted: Fri Apr 12, 2019 2:22 pm
by Gabriela
Hello,

Here is a new recently published tutorial about TWAIN features, that covers your question (see the section 4.Acquire from the source):
https://www.docuvieware.com/guides/aspn ... eware.html