In-process viewing while scanning

Discussions about TWAIN & WIA scanning in GdPicture.NET using GdPictureImaging.
Post Reply
pjbnet
Posts: 5
Joined: Tue Jan 31, 2012 1:17 pm

WPF Viewer Previewing whilst capturing images using TWAIN

Post by pjbnet » Thu Jun 18, 2015 11:24 am

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;
                        };


AH15
Posts: 1
Joined: Mon May 23, 2016 2:10 pm

In-process viewing while scanning

Post by AH15 » Mon May 23, 2016 2:17 pm

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

Gabriela
Posts: 436
Joined: Wed Nov 22, 2017 9:52 am

Re: In-process viewing while scanning

Post by Gabriela » Fri Apr 12, 2019 2:22 pm

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

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest