Scanning Fails after me.close

Discussions about TWAIN & WIA scanning in GdPicture.NET using GdPictureImaging.
Post Reply
jdomkus
Posts: 3
Joined: Mon Dec 15, 2008 7:12 pm

Scanning Fails after me.close

Post by jdomkus » Fri Nov 20, 2009 10:54 pm

I have a scanning application that once I do a me.close on the form and then go back in to try to scan something it gives a error that the computer cannot communicate with the scanner.

If I just do a me.visible=false and then go back in it works fine

Any ideas on why this is happening?

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Scanning Fails after me.close

Post by Loïc » Sat Nov 21, 2009 12:33 pm

Hi,

How to reproduce your problem ? The information you gave are not sufficient for investigation.

Maybe you have to unload the TWAIN source manager before calling "me.close" ? See method TwainUnloadSourceManager.

Kind regards,

Loïc

jdomkus
Posts: 3
Joined: Mon Dec 15, 2008 7:12 pm

Re: Scanning Fails after me.close

Post by jdomkus » Sun Nov 22, 2009 6:18 pm

Loic,

I just took your twain sample and created a new form (form2) with two buttons (One scan and one return), Then I copied all of your code from behind the scan all document feeder (adf) into jpeg files and pasted that behind the scan button on form2. I also commented out the initscanconfig, applyimagefilters and check preview routines. Behind the return button I have a me.close and I also make form1.visible=true

When I click the scan button (I created) on form2 the first time it scans all documents fine, then I press the return button to return to the first screen. If I try to go to form2 again to scan, It either just sits at the scanner screen or gives me a error that it cannot connect to the scanner.

Below is the code behind the scan button on form 2, Behind the return button is only me.close and form1.visible=true

'Here we will scan in a 24bpp & 300 DPI from ADF into separate jpeg files
Dim nImageCount As Integer
Dim ImageID As Integer
Dim oGdPictureImaging As New GdPictureImaging

If oGdPictureImaging.TwainOpenDefaultSource(Me.Handle) Then
nImageCount = 0

'InitScanConfig()

oGdPictureImaging.TwainSetAutoFeed(True) 'Set AutoFeed Enabled
oGdPictureImaging.TwainSetAutoScan(True) 'To achieve the maximum scanning rate
oGdPictureImaging.TwainSetResolution(300)
oGdPictureImaging.TwainSetPixelType(TwainPixelType.TWPT_RGB) 'RGB
oGdPictureImaging.TwainSetBitDepth(8) ' 24 bpp

Do
ImageID = oGdPictureImaging.TwainAcquireToGdPictureImage(Me.Handle)
If ImageID <> 0 Then
'Call ApplyImageFilters(ImageID)
'If chkPreview.CheckState = 1 Then Call DisplayImage(ImageID)
nImageCount = nImageCount + 1
Call oGdPictureImaging.SaveAsJPEG(ImageID, My.Application.Info.DirectoryPath & "\image" & Trim(Str(nImageCount)) & ".jpg", 75)
Call oGdPictureImaging.ReleaseGdPictureImage(ImageID)
End If
Loop While oGdPictureImaging.TwainGetState > TwainStatus.TWAIN_SOURCE_ENABLED

Call oGdPictureImaging.TwainCloseSource()
MsgBox("Done !")
Else
MsgBox("can't open default source, twain state is: " & oGdPictureImaging.TwainGetState.ToString)
End If

Thanks for your help

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Scanning Fails after me.close

Post by Loïc » Sun Nov 22, 2009 6:34 pm

Hi,

Could you try TwainCloseSourceManager() instead of TwainCloseSource() ?

Kind regards,

Loïc

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests