|
Found my own answer, the Scanner window seems like it has to be either the main, or the only window in the app.
|
|
|
|
|
palease tell me how to setup the scanner auto scan?
thanks!!!
|
|
|
|
|
please tell me how to check status ?
|
|
|
|
|
it is so cool and professionnal class programming. could you give me the information about the functions which are used in the classes? or is there any documentation about the twain_32?
|
|
|
|
|
I have successfully used your app for scanning apps on a WinXP machine with a Xerox Documate 510 scanner but if I use the same app and scanner on a WIN2K machine the scanner driver that gets installed on WIN2K is old or different for XEROX as a result the code launches the old driver for scanning and the application does not work with this old driver
My question is does this code require WIA capable scan drivers to work successfully ?
specifically if I loop through the code the for certain drivers the DSevent call returns back a
TwRC.NotDSEvent and hence the scanning does not proceed.
Any help would be appreciated.
Thanks
|
|
|
|
|
samething here on ricoh 1515 work fine but on epson gt 2500 have the same error , loop then loop and then loop very weirdo
|
|
|
|
|
how to copy the image to clipboard?
|
|
|
|
|
Clipboard.SetImage(image);
Best regards,
Christian
|
|
|
|
|
After view the file in viewer i cannot delete it. I've the error:
The process cannot access the file 'C:\ny.jpg' because it is being used by another process.
Any solutions?
|
|
|
|
|
I solve de problem. I must dispose and set to nothing all images before try delete the file.
|
|
|
|
|
Hi,All
I sovled the problem by the following codes:
_MODIDocument.Close(false);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(_MODIDocument);
System.Runtime.InteropServices.Marshal.ReleaseComObject(_MODIDocument);
GC.Collect();
MODI.Document _NULLMODIDocument = new MODI.Document();
_NULLMODIDocument.Create(string.Empty);
axMiDocView1.Document = _NULLMODIDocument;
File.Delete(_filename);
It was done.Good luck!
1
|
|
|
|
|
Hi '
I am in a process of developing, ASP.NET (C Sharp) Document Scanning application? Kindly guide me how to use this to build such application.
Thanks,
Ali Mustapha
Life is too short to be counted, enjoy life.
|
|
|
|
|
Thanks for sharing!
|
|
|
|
|
I am trying to develop an app in VB.net.. wich
1) scan a doc without user interface
2) changing the resolution,dpi , black&white.. programmaticaly...
3) saving the scan image as a tiff in hard drive..
Anyone can help? EVEN with C#
|
|
|
|
|
|
Hello,
Someone knows if is possible to do invisible the window that appear with a progressbar that indicate scanning...
Thank you for your help.
|
|
|
|
|
Plis!!!
I Need the source code for my applications VB
I Need Really...
I'm New....
Thank You Very Much...
|
|
|
|
|
http://www.codeplex.com/openTwain, it used to be over on gotdotnet, but gotdotnet is closing so it moved.
|
|
|
|
|
Hi!
When I use TWAIN Gui as a stand-alone program, everything works fine, but when I use it as invoked form from my application, Init() method could hang up whole application. I traced into code and found out, that error is generated in Twainlib.cs at line 60:
TwRC rc = DSMparent( appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.OpenDSM, ref hwndp );
What is wrong here? Sometimes it works, sometimes not!
|
|
|
|
|
I've got the same problem.
All of a sudden it returns always Failure.
thnx.
DiMann wrote: When I use TWAIN Gui as a stand-alone program, everything works fine, but when I use it as invoked form from my application, Init() method could hang up whole application. I traced into code and found out, that error is generated in Twainlib.cs at line 60:
TwRC rc = DSMparent( appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.OpenDSM, ref hwndp );
What is wrong here? Sometimes it works, sometimes not!
Ronald
|
|
|
|
|
I Need The Source Code for an application VB please...
Thanks. I'm New.
Spanish....
Necesito el Codigo para una aplicacion VB por favor...
Gracias. Soy Nuevo.
PHALCOM2.
Favio.
|
|
|
|
|
|
i converted part of it to VB and am using it, email me if you want the classes
josh at pipeline dot com
|
|
|
|
|
TwainLib.vb
Imports System
Imports System.Collections
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Namespace TwainLib
Public Enum TwainCommand
[Not] = -1
Null = 0
TransferReady = 1
CloseRequest = 2
CloseOk = 3
DeviceEvent = 4
Failure = 5
End Enum
Public Class Twain
Private hwnd As IntPtr
Private appid As TwIdentity
Private srcds As TwIdentity
Private evtmsg As TwEvent
Private winmsg_m As WINMSG_S
<DllImport("twain_32.dll", EntryPoint:="#1")> Private Shared Function DSMparent(<[In](), Out()> ByVal origin As TwIdentity, ByVal zeroptr As IntPtr, ByVal dg As TwDG, ByVal dat As TwDAT, ByVal msg As TwMSG, ByRef refptr As IntPtr) As TwRC
End Function
<DllImport("twain_32.dll", EntryPoint:="#1")> Private Shared Function DSMident(<[In](), Out()> ByVal origin As TwIdentity, ByVal zeroptr As IntPtr, ByVal dg As TwDG, ByVal dat As TwDAT, ByVal msg As TwMSG, <[In](), Out()> ByVal idds As TwIdentity) As TwRC
End Function
<DllImport("twain_32.dll", EntryPoint:="#1")> Private Shared Function DSMstatus(<[In](), Out()> ByVal origin As TwIdentity, ByVal zeroptr As IntPtr, ByVal dg As TwDG, ByVal dat As TwDAT, ByVal msg As TwMSG, <[In](), Out()> ByVal dsmstat As TwStatus) As TwRC
End Function
<DllImport("twain_32.dll", EntryPoint:="#1")> Private Shared Function DSuserif(<[In](), Out()> ByVal origin As TwIdentity, <[In](), Out()> ByVal dest As TwIdentity, ByVal dg As TwDG, ByVal dat As TwDAT, ByVal msg As TwMSG, ByVal guif As TwUserInterface) As TwRC
End Function
<DllImport("twain_32.dll", EntryPoint:="#1")> Private Shared Function DSevent(<[In](), Out()> ByVal origin As TwIdentity, <[In](), Out()> ByVal dest As TwIdentity, ByVal dg As TwDG, ByVal dat As TwDAT, ByVal msg As TwMSG, ByRef evt As TwEvent) As TwRC
End Function
<DllImport("twain_32.dll", EntryPoint:="#1")> Private Shared Function DSstatus(<[In](), Out()> ByVal origin As TwIdentity, <[In]()> ByVal dest As TwIdentity, ByVal dg As TwDG, ByVal dat As TwDAT, ByVal msg As TwMSG, <[In](), Out()> ByVal dsmstat As TwStatus) As TwRC
End Function
<DllImport("twain_32.dll", EntryPoint:="#1")> Private Shared Function DScap(<[In](), Out()> ByVal origin As TwIdentity, <[In]()> ByVal dest As TwIdentity, ByVal dg As TwDG, ByVal dat As TwDAT, ByVal msg As TwMSG, <[In](), Out()> ByVal capa As TwCapability) As TwRC
End Function
<DllImport("twain_32.dll", EntryPoint:="#1")> Private Shared Function DSiinf(<[In](), Out()> ByVal origin As TwIdentity, <[In]()> ByVal dest As TwIdentity, ByVal dg As TwDG, ByVal dat As TwDAT, ByVal msg As TwMSG, <[In](), Out()> ByVal imginf As TwImageInfo) As TwRC
End Function
<DllImport("twain_32.dll", EntryPoint:="#1")> Private Shared Function DSixfer(<[In](), Out()> ByVal origin As TwIdentity, <[In]()> ByVal dest As TwIdentity, ByVal dg As TwDG, ByVal dat As TwDAT, ByVal msg As TwMSG, ByRef hbitmap As IntPtr) As TwRC
End Function
<DllImport("twain_32.dll", EntryPoint:="#1")> Private Shared Function DSpxfer(<[In](), Out()> ByVal origin As TwIdentity, <[In]()> ByVal dest As TwIdentity, ByVal dg As TwDG, ByVal dat As TwDAT, ByVal msg As TwMSG, <[In](), Out()> ByVal pxfr As TwPendingXfers) As TwRC
End Function
<DllImport("twain_32.dll", EntryPoint:="#1")> Private Shared Function DSilayout(<[In](), Out()> ByVal origin As TwIdentity, <[In](), Out()> ByVal dest As TwIdentity, ByVal dg As TwDG, ByVal dat As TwDAT, ByVal msg As TwMSG, <[In](), Out()> ByVal imglo As TwImageLayout) As TwRC
End Function
<DllImport("twain_32.dll", EntryPoint:="#1")> Private Shared Function DSMlayout(<[In](), Out()> ByVal origin As TwIdentity, <[In](), Out()> ByVal dest As TwIdentity, ByVal dg As TwDG, ByVal dat As TwDAT, ByVal msg As TwMSG, <[In](), Out()> ByVal imglo As IntPtr) As TwRC
End Function
<DllImport("kernel32.dll", ExactSpelling:=True)> Friend Shared Function GlobalAlloc(ByVal flags As Integer, ByVal size As Integer) As IntPtr
End Function
<DllImport("kernel32.dll", ExactSpelling:=True)> Friend Shared Function GlobalLock(ByVal handle As IntPtr) As IntPtr
End Function
<DllImport("kernel32.dll", ExactSpelling:=True)> Friend Shared Function GlobalUnlock(ByVal handle As IntPtr) As Boolean
End Function
<DllImport("kernel32.dll", ExactSpelling:=True)> Friend Shared Function GlobalFree(ByVal handle As IntPtr) As IntPtr
End Function
<DllImport("user32.dll", ExactSpelling:=True)> Private Shared Function GetMessagePos() As Integer
End Function
<DllImport("user32.dll", ExactSpelling:=True)> Private Shared Function GetMessageTime() As Integer
End Function
<DllImport("gdi32.dll", ExactSpelling:=True)> Private Shared Function GetDeviceCaps(ByVal hDC As IntPtr, ByVal nIndex As Integer) As Integer
End Function
<DllImport("gdi32.dll", CharSet:=CharSet.Auto)> Private Shared Function CreateDC(ByVal szdriver As String, ByVal szdevice As String, ByVal szoutput As String, ByVal devmode As IntPtr) As IntPtr
End Function
<DllImport("gdi32.dll", ExactSpelling:=True)> Private Shared Function DeleteDC(ByVal hdc As IntPtr) As Boolean
End Function
Private Const CountryUSA As Short = 1
Private Const LanguageUSA As Short = 13
Public Sub New()
appid = New TwIdentity
appid.Id = IntPtr.Zero
appid.Version.MajorNum = 1
appid.Version.MinorNum = 1
appid.Version.Language = LanguageUSA
appid.Version.Country = CountryUSA
appid.Version.Info = "TWAIN Scanner"
appid.ProtocolMajor = TwProtocol.Major
appid.ProtocolMinor = TwProtocol.Minor
appid.SupportedGroups = CType(TwDG.Image Or TwDG.Control, Integer)
appid.Manufacturer = "Kod Efisien Sdn Bhd"
appid.ProductFamily = "TWAIN 32 Scanner"
appid.ProductName = "ScanSoft"
srcds = New TwIdentity
srcds.Id = IntPtr.Zero
evtmsg.EventPtr = Marshal.AllocHGlobal(Marshal.SizeOf(winmsg_m))
End Sub
Public Sub Dispose()
Marshal.FreeHGlobal(evtmsg.EventPtr)
End Sub
Protected Overrides Sub Finalize()
Marshal.FreeHGlobal(evtmsg.EventPtr)
End Sub
Public Sub Init(ByVal hwndp As IntPtr)
Finish()
Dim rc As TwRC = DSMparent(appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.OpenDSM, hwndp)
If (rc = TwRC.Success) Then
rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.GetDefault, srcds)
If (rc = TwRC.Success) Then
hwnd = hwndp
Else
rc = DSMparent(appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.CloseDSM, hwndp)
End If
End If
End Sub
Public Sub [Select](Optional ByRef Model As String = "")
Dim rc As TwRC
CloseSrc()
If Equals(appid.Id, IntPtr.Zero) = True Then
Init(hwnd)
If Equals(appid.Id, IntPtr.Zero) = True Then
Return
End If
End If
rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.UserSelect, srcds)
Model = srcds.ProductName.ToString
End Sub
Public Sub [SelectDefault](Optional ByRef Model As String = "")
Dim rc As TwRC
CloseSrc()
If Equals(appid.Id, IntPtr.Zero) = True Then
Init(hwnd)
If Equals(appid.Id, IntPtr.Zero) = True Then
Return
End If
End If
rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.GetDefault, srcds)
Model = srcds.ProductName.ToString
End Sub
Public Sub Acquire(Optional ByVal PaperSize As TwSS = TwSS.TwSS_A4, Optional ByVal XScale As Single = 1, _
Optional ByVal YScale As Single = 1, Optional ByVal SColor As TwColourType = TwColourType.twRGB, _
Optional ByVal TopMargin As Single = 0.0, Optional ByVal LeftMargin As Single = 0.0, _
Optional ByVal RightMargin As Single = 0.0, Optional ByVal BottomMargin As Single = 0.0, _
Optional ByVal FrameNumber As Integer = 1, Optional ByVal PageNumber As Integer = 1, _
Optional ByVal DocumentNumber As Integer = 1)
Dim rc As TwRC
CloseSrc()
If Equals(appid.Id, IntPtr.Zero) = True Then
Init(hwnd)
If Equals(appid.Id, IntPtr.Zero) = True Then
Return
End If
End If
rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.OpenDS, srcds)
If (rc <> TwRC.Success) Then
Return
End If
'Set Unit to Pixels
Dim Pixels As TwUnit = TwUnit.twPIXELS
Dim capUnit As TwCapability = New TwCapability(TwCap.IUnits, Pixels, TwType.Int16)
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capUnit)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
''Set X Resolution
'Dim XResolution As Single = 1
'Dim capX As TwCapability = New TwCapability(TwCap.XResolution, XResolution, TwType.Fix32)
'rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capX)
'If rc <> TwRC.Success Then
' CloseSrc()
' Return
'End If
''Set Y Resolution
'Dim capY As TwCapability = New TwCapability(TwCap.YResolution, YResolution, TwType.Fix32)
'rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capY)
'If rc <> TwRC.Success Then
' CloseSrc()
' Return
'End If
Dim xcap As TwCapability = New TwCapability(TwCap.XScaling, XScale, TwType.Fix32)
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, xcap)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
xcap = New TwCapability(TwCap.YScaling, YScale, TwType.Fix32)
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, xcap)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
Dim ps As TwCapability = New TwCapability(TwCap.SupportedSizes, PaperSize, TwType.Int16)
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, ps)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
'Set Layout
Dim Layout As TwImageLayout = New TwImageLayout
rc = DSilayout(appid, srcds, TwDG.Image, TwDAT.ImageLayout, TwMSG.Get, Layout)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
If TopMargin > 0 Then
Layout.Frame.Top.FromFloat(CSng(TopMargin))
End If
If LeftMargin > 0 Then
Layout.Frame.Left.FromFloat(CSng(LeftMargin))
End If
If RightMargin > 0 Then
Layout.Frame.Right.FromFloat(CSng(RightMargin))
End If
If BottomMargin > 0 Then
Layout.Frame.Bottom.FromFloat(CSng(BottomMargin))
End If
Layout.FrameNumber = 1
Layout.PageNumber = 1
Layout.DocumentNumber = 1
rc = Me.DSilayout(appid, srcds, TwDG.Image, TwDAT.ImageLayout, TwMSG.Set, Layout)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
'Dim ptr1 As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(Layout))
'Marshal.StructureToPtr(Layout, ptr1, False)
'rc = Me.DSMlayout(appid, srcds, TwDG.Image, TwDAT.ImageLayout, TwMSG.Get, ptr1)
'If rc <> TwRC.Success Then
' CloseSrc()
' Return
'End If
''Dim ptr2 As IntPtr = ptr1
'Marshal.PtrToStructure(ptr1, Layout)
'If TopMargin > 0 Then
' Layout.Frame.Top.FromFloat(CSng(TopMargin))
'End If
'If LeftMargin > 0 Then
' Layout.Frame.Left.FromFloat(CSng(LeftMargin))
'End If
'If RightMargin > 0 Then
' Layout.Frame.Right.FromFloat(CSng(RightMargin))
'End If
'If BottomMargin > 0 Then
' Layout.Frame.Bottom.FromFloat(CSng(BottomMargin))
'End If
'Layout.FrameNumber = 1
'Layout.PageNumber = 1
'Layout.DocumentNumber = 1
'Marshal.StructureToPtr(Layout, ptr1, True)
'rc = Me.DSMlayout(appid, srcds, TwDG.Image, TwDAT.ImageLayout, TwMSG.Set, ptr1)
'If rc <> TwRC.Success Then
' CloseSrc()
' Return
'End If
'Scan Colour
Dim Ccap As TwCapability = New TwCapability(TwCap.IPixelType, SColor, TwType.UInt16)
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, Ccap)
If (rc <> TwRC.Success) Then
CloseSrc()
Return
End If
Dim cap As TwCapability = New TwCapability(TwCap.XferCount, 1, TwType.Int16)
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap)
If (rc <> TwRC.Success) Then
CloseSrc()
Return
End If
Dim guif As TwUserInterface = New TwUserInterface
guif.ShowUI = 1
guif.ModalUI = 1
guif.ParentHand = hwnd
rc = DSuserif(appid, srcds, TwDG.Control, TwDAT.UserInterface, TwMSG.EnableDS, guif)
If (rc <> TwRC.Success) Then
CloseSrc()
Return
End If
End Sub
Public Function TransferPictures() As ArrayList
Dim pics As ArrayList = New ArrayList
If Equals(srcds.Id, IntPtr.Zero) Then
Return pics
End If
Dim rc As TwRC
Dim hbitmap As IntPtr = IntPtr.Zero
Dim pxfr As TwPendingXfers = New TwPendingXfers
Do
pxfr.Count = 0
hbitmap = IntPtr.Zero
Dim iinf As TwImageInfo = New TwImageInfo
rc = DSiinf(appid, srcds, TwDG.Image, TwDAT.ImageInfo, TwMSG.Get, iinf)
If (rc <> TwRC.Success) Then
CloseSrc()
Return pics
End If
'StartScan
rc = DSixfer(appid, srcds, TwDG.Image, TwDAT.ImageNativeXfer, TwMSG.Get, hbitmap)
If (rc <> TwRC.XferDone) Then
CloseSrc()
Return pics
End If
rc = DSpxfer(appid, srcds, TwDG.Control, TwDAT.PendingXfers, TwMSG.EndXfer, pxfr)
If (rc <> TwRC.Success) Then
CloseSrc()
Return pics
End If
pics.Add(hbitmap)
Loop While (pxfr.Count <> 0)
rc = DSpxfer(appid, srcds, TwDG.Control, TwDAT.PendingXfers, TwMSG.Reset, pxfr)
Return pics
End Function
Public Function PassMessage(ByVal m As Message) As TwainCommand
If Equals(srcds.Id, IntPtr.Zero) Then
Return TwainCommand.Not
End If
Dim pos As Integer = GetMessagePos()
winmsg_m.hwnd = m.HWnd
winmsg_m.message = m.Msg
winmsg_m.wParam = m.WParam
winmsg_m.lParam = m.LParam
winmsg_m.time = GetMessageTime()
winmsg_m.x = pos 'CType(pos, Short)
winmsg_m.y = Int(pos / 2 ^ 16) 'CType(Int(pos / 2 ^ 16), Short)
Marshal.StructureToPtr(winmsg_m, evtmsg.EventPtr, False)
evtmsg.Message = 0
Dim rc As TwRC = DSevent(appid, srcds, TwDG.Control, TwDAT.Event, TwMSG.ProcessEvent, evtmsg)
If (rc = TwRC.NotDSEvent) Then
Return TwainCommand.Not
End If
If (rc = TwRC.Failure) Then
Return TwainCommand.Failure
End If
If (evtmsg.Message = CType(TwMSG.XFerReady, Short)) Then
Return TwainCommand.TransferReady
End If
If (evtmsg.Message = CType(TwMSG.CloseDSReq, Short)) Then
Return TwainCommand.CloseRequest
End If
If (evtmsg.Message = CType(TwMSG.CloseDSOK, Short)) Then
Return TwainCommand.CloseOk
End If
If (evtmsg.Message = CType(TwMSG.DeviceEvent, Short)) Then
Return TwainCommand.DeviceEvent
End If
Return TwainCommand.Null
End Function
Public Sub CloseSrc()
Dim rc As TwRC
If Not Equals(srcds.Id, IntPtr.Zero) Then
Dim guif As TwUserInterface = New TwUserInterface
rc = DSuserif(appid, srcds, TwDG.Control, TwDAT.UserInterface, TwMSG.DisableDS, guif)
rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.CloseDS, srcds)
End If
End Sub
Public Sub Finish()
Dim rc As TwRC
CloseSrc()
If Not Equals(appid.Id, IntPtr.Zero) Then
rc = DSMparent(appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.CloseDSM, hwnd)
End If
appid.Id = IntPtr.Zero
End Sub
Public Shared ReadOnly Property ScreenBitDepth() As Integer
Get
Dim screenDC As IntPtr = CreateDC("DISPLAY", Nothing, Nothing, IntPtr.Zero)
Dim bitDepth As Integer = GetDeviceCaps(screenDC, 12)
bitDepth *= GetDeviceCaps(screenDC, 14)
DeleteDC(screenDC)
Return bitDepth
End Get
End Property
<StructLayout(LayoutKind.Sequential, Pack:=4)> Friend Structure WINMSG_S
Public hwnd As IntPtr
Public message As Integer
Public wParam As IntPtr
Public lParam As IntPtr
Public time As Integer
Public x As Integer
Public y As Integer
End Structure
End Class
End Namespace
|
|
|
|
|
TwainDefs.vb
Imports System
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Namespace TwainLib
Public Class TwProtocol
Public Const Major As Short = 1
Public Const Minor As Short = 9
End Class
#Region " Enums "
<Flags()> Friend Enum TwDG As Short
Control = &H1
Image = &H2
Audio = &H4
End Enum
Friend Enum TwDAT As Short
Null = &H0
Capability = &H1
[Event] = &H2
Identity = &H3
Parent = &H4
PendingXfers = &H5
SetupMemXfer = &H6
SetupFileXfer = &H7
Status = &H8
UserInterface = &H9
XferGroup = &HA
TwunkIdentity = &HB
CustomDSData = &HC
DeviceEvent = &HD
FileSystem = &HE
PassThru = &HF
ImageInfo = &H101
ImageLayout = &H102
ImageMemXfer = &H103
ImageNativeXfer = &H104
ImageFileXfer = &H105
CieColor = &H106
GrayResponse = &H107
RGBResponse = &H108
JpegCompression = &H109
Palette8 = &H10A
ExtImageInfo = &H10B
SetupFileXfer2 = &H301
End Enum
Friend Enum TwMSG As Short
Null = &H0
[Get] = &H1
GetCurrent = &H2
GetDefault = &H3
GetFirst = &H4
GetNext = &H5
[Set] = &H6
Reset = &H7
QuerySupport = &H8
XFerReady = &H101
CloseDSReq = &H102
CloseDSOK = &H103
DeviceEvent = &H104
CheckStatus = &H201
OpenDSM = &H301
CloseDSM = &H302
OpenDS = &H401
CloseDS = &H402
UserSelect = &H403
DisableDS = &H501
EnableDS = &H502
EnableDSUIOnly = &H503
ProcessEvent = &H601
EndXfer = &H701
StopFeeder = &H702
ChangeDirectory = &H801
CreateDirectory = &H802
Delete = &H803
FormatMedia = &H804
GetClose = &H805
GetFirstFile = &H806
GetInfo = &H807
GetNextFile = &H808
Rename = &H809
Copy = &H80A
AutoCaptureDir = &H80B
PassThru = &H901
End Enum
Friend Enum TwRC As Short
Success = &H0
Failure = &H1
CheckStatus = &H2
Cancel = &H3
DSEvent = &H4
NotDSEvent = &H5
XferDone = &H6
EndOfList = &H7
InfoNotSupported = &H8
DataNotAvailable = &H9
End Enum
Friend Enum TwCC As Short
Success = &H0
Bummer = &H1
LowMemory = &H2
NoDS = &H3
MaxConnections = &H4
OperationError = &H5
BadCap = &H6
BadProtocol = &H9
BadValue = &HA
SeqError = &HB
BadDest = &HC
CapUnsupported = &HD
CapBadOperation = &HE
CapSeqError = &HF
Denied = &H10
FileExists = &H11
FileNotFound = &H12
NotEmpty = &H13
PaperJam = &H14
PaperDoubleFeed = &H15
FileWriteError = &H16
CheckDeviceOnline = &H17
End Enum
Friend Enum TwOn As Short
Array = &H3
[Enum] = &H4
One = &H5
Range = &H6
DontCare = -1
End Enum
Friend Enum TwType As Short
Int8 = &H0
Int16 = &H1
Int32 = &H2
UInt8 = &H3
UInt16 = &H4
UInt32 = &H5
Bool = &H6
Fix32 = &H7
Frame = &H8
Str32 = &H9
Str64 = &HA
Str128 = &HB
Str255 = &HC
Str1024 = &HD
Str512 = &HE
End Enum
Friend Enum TwCap As Short
XferCount = &H1
ICompression = &H100
IPixelType = &H101
IUnits = &H102
IXferMech = &H103
BitDepth = &H112B
ImageFileFormat = &H110C
XResolution = &H1118
YResolution = &H1119
ImageWidth = &H1116
ImageLength = &H1117
SupportedSizes = &H1122
XScaling = &H1124
YScaling = &H1125
End Enum
Public Enum TwSS As Short
TwSS_None = &H0
TwSS_A4 = &H1
TwSS_B5Letter = &H2
TwSS_USLetter = &H3
End Enum
Public Enum TwColourType As Short
twBW = 0
twGREY = 1
twRGB = 2
End Enum
Public Enum TwUnit As Short
tw_PICAS = 2
twCENTIMETERS = 1
twINCHES = 0
twPIXELS = 5
twPOINTS = 3
twTWIPS = 4
End Enum
#End Region
<StructLayout(LayoutKind.Sequential, Pack:=2, CharSet:=CharSet.Ansi)> Friend Class TwIdentity
Public Id As IntPtr
Public Version As TwVersion
Public ProtocolMajor As Short
Public ProtocolMinor As Short
Public SupportedGroups As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=34)> Public Manufacturer As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=34)> Public ProductFamily As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=34)> Public ProductName As String
End Class
<StructLayout(LayoutKind.Sequential, Pack:=2, CharSet:=CharSet.Ansi)> Friend Structure TwVersion
Public MajorNum As Short
Public MinorNum As Short
Public Language As Short
Public Country As Short
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=34)> Public Info As String
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Class TwUserInterface
Public ShowUI As Short
Public ModalUI As Short
Public ParentHand As IntPtr
End Class
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Class TwStatus
Public ConditionCode As Short
Public Reserved As Short
End Class
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Structure TwEvent
Public EventPtr As IntPtr
Public Message As Short
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Class TwImageInfo
Public XResolution As Int32
Public YResolution As Int32
Public ImageWidth As Int32
Public ImageLength As Int32
Public SamplesPerPixel As Int16
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=8)> Public BitsPerSample() As Short
Public BitsPerPixel As Int16
Public Planar As Boolean
Public PixelType As Int16
Public Compression As Short
End Class
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Class TwPendingXfers
Public Count As Short
Public EOJ As Integer
End Class
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Structure TwFix32
Public Whole As System.Int16
Public Frac As System.UInt32
Public Function ToFloat() As Single
Dim frac_sng As Single
frac_sng = System.Convert.ToSingle(Frac)
Return CType(Whole + (CType(frac_sng, Single) / 65536.0F), Single)
End Function
Public Sub FromFloat(ByVal f As Single)
Dim i As Int32 = CType(((f * 65536.0F) + 0.5F), Int32)
Whole = System.Convert.ToInt16(i / 2 ^ 16)
Frac = System.Convert.ToUInt32((i Or &HFFFF))
End Sub
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Structure TwFrame
Public Left As TwFix32
Public Top As TwFix32
Public Right As TwFix32
Public Bottom As TwFix32
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Class TwImageLayout
Public Frame As TwFrame
Public DocumentNumber As Integer
Public PageNumber As Integer
Public FrameNumber As Integer
End Class
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Class TwCapability
Public Cap As Short
Public ConType As Short
Public Handle As IntPtr
Public Sub TwCapability(ByVal capIn As TwCap)
Cap = CType(capIn, Short)
ConType = -1
End Sub
Public Sub New(ByVal capIn As TwCap, ByVal sval As Short, ByVal TWType As TwType)
Cap = CType(capIn, Short)
ConType = CType(TwOn.One, Short)
Handle = Twain.GlobalAlloc(&H42, 6)
Dim pv As IntPtr = Twain.GlobalLock(Handle)
Marshal.WriteInt16(pv, 0, CType(TWType, Short))
Marshal.WriteInt32(pv, 2, CType(sval, Short))
Twain.GlobalUnlock(Handle)
End Sub
Public Sub Dispose()
If Not Equals(Handle, IntPtr.Zero) Then
Twain.GlobalFree(Handle)
End If
End Sub
Protected Overrides Sub Finalize()
If Not Equals(Handle, IntPtr.Zero) Then
Twain.GlobalFree(Handle)
End If
End Sub
End Class
End Namespace
|
|
|
|
|