I'm having a problem with scanning.
I thought I would have a class to setup twain properties, start the scan and return a list of images
Code: Select all
Public Class GDTwainSetup
Private Profile As ScanProfile
Private oGdPictureImaging As GdPictureImaging
Private PageCounter As Integer
Private ThisIntPtr As System.IntPtr
Public Sub New(ByVal mProfile As ScanProfile, ByVal Handel As System.IntPtr)
Profile = mProfile
ThisIntPtr = Handel
End Sub
Public Function RunScan() As List(Of Bitmap)
Dim lst As New List(Of Bitmap)
oGdPictureImaging = New GdPictureImaging()
oGdPictureImaging.SetLicenseNumber("")
oGdPictureImaging.TwainLogStart("c:\temp\gdtwain.log")
If oGdPictureImaging.TwainGetSourceCount(IntPtr.Zero) = 0 Then
MessageBox.Show("No scanner found")
Return Nothing
End If
Init
If oGdPictureImaging.TwainGetState() = TwainStatus.TWAIN_SOURCE_OPEN Then
Do
ImageID = oGdPictureImaging.TwainAcquireToGdPictureImage(ThisIntPtr)
If ImageID = 0 Then
oGdPictureImaging.TwainCloseSource()
Exit Do
End If
If (Profile.EnableDuplex And oGdPictureImaging.IsBlank(ImageID, CSng(Profile.SetBlankPageThreshold / 100))) Then
oGdPictureImaging.ReleaseGdPictureImage(ImageID)
Else
ApplyImageFilters(ImageID, oGdPictureImaging)
lst.Add(oGdPictureImaging.GetBitmapFromGdPictureImage(ImageID))
End If
oGdPictureImaging.ReleaseGdPictureImage(ImageID)
Loop While oGdPictureImaging.TwainGetState = TwainStatus.TWAIN_SOURCE_ENABLED
end if
End Function
Private Sub Init()
Dim Status As Boolean = False
If Profile.Source.Trim().Length > 0 Then
Try
oGdPictureImaging.TwainCloseSource()
oGdPictureImaging.TwainCloseSourceManager(IntPtr.Zero)
blnStaus = oGdPictureImaging.TwainOpenSource(IntPtr.Zero, Profile.Source) "Errors here"
Catch
Staus = oGdPictureImaging.TwainOpenDefaultSource(IntPtr.Zero)
End Try
Else
oGdPictureImaging.TwainCloseSource()
oGdPictureImaging.TwainCloseSourceManager(IntPtr.Zero)
Staus = oGdPictureImaging.TwainOpenDefaultSource(IntPtr.Zero)
End If
End Sub
Attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.
I know I can change the Debug > exception > Managed Debugging Assistants and unchecked LoaderLock, I don't want to do that if when built it causes problem on user computer.
The demo's and posts I see run code in the form. Should this method work, do I need to have the code in the from and use its handle?
spec
Windows xp sp3
Visual studio 2008
gdPicture 7.4.0.1
Thanks