Basic Univers
; EZ_Twain DLL
;(W) umsetzung nach PB by Galaxy, 03/2003

; global für DLL
Global *TWAIN_IsAvailable
Global *TWAIN_SelectImageSource
Global *TWAIN_AcquireToClipboard
Global *TWAIN_AcquireNative
Global *TWAIN_WriteNativeToFilename
Global *TWAIN_FreeNative

Procedure Twain_Init()         ; dll Init
OpenLibrary(10, "web_cam.DLL")
*TWAIN_IsAvailable = IsFunction(10, "TWAIN_IsAvailable")
*TWAIN_SelectImageSource = IsFunction(10, "TWAIN_SelectImageSource")
*TWAIN_AcquireToClipboard = IsFunction(10, "TWAIN_AcquireToClipboard")
*TWAIN_AcquireNative = IsFunction(10, "TWAIN_AcquireNative")
*TWAIN_WriteNativeToFilename = IsFunction(10, "TWAIN_WriteNativeToFilename")
*TWAIN_FreeNative = IsFunction(10, "TWAIN_FreeNative")
EndProcedure

Procedure.l Twain_ScannCheck()
; Check, ob TWAIN Scanner vorhanden ist
; 0 = Kein Scanner vorhanden oder kein TWAIN Scanner
; 1 = OK, Scanner gefunden

value.l = CallFunctionFast(*TWAIN_IsAvailable)
ProcedureReturn value
EndProcedure

Procedure.l Twain_scanchoice(hwnd)
; Auswahl des Scanners
; 0 = Kein Scanner vorhanden / Auswahl abgebrochen
; 1 = OK, Scanner wurde gewählt

  value.l = CallFunctionFast(*TWAIN_SelectImageSource, hwnd)
  ProcedureReturn value
EndProcedure


Procedure Twain_ScannToFile(datei.s)
; scannt als Datei

  bmp.l = CallFunctionFast(*TWAIN_AcquireNative, 0, 0)
          CallFunctionFast(*TWAIN_WriteNativeToFilename, bmp, datei)
          CallFunctionFast(*TWAIN_FreeNative, bmp)
ProcedureReturn 0
EndProcedure

Procedure TWAIN_ScannToClip()
; scannt in die Zwischenablage

CallFunctionFast(*TWAIN_AcquireToClipboard, 0, 0)
ProcedureReturn 0
EndProcedure


; ******************************************* Twain *****************

; demo
WindowID = OpenWindow(0, 700, 10, 320, 400, #PB_Window_SystemMenu, "Test")
CreateGadgetList(WindowID())


Twain_Init()                        ; dll init
If Twain_ScannCheck() = 1           ; Scanner erkennen und prüfen
Twain_scanchoice(WindowID)         ; Scanner wählen
Twain_ScannToFile("scantest.bmp")  ; Bild scannen
EndIf



Repeat
eventID.l = WaitWindowEvent()
Until EventID = #PB_EventCloseWindow