Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/Picture/Twain/Twain
Function:
Required plugins for this example: MBS Picture Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Picture/Twain/Twain
This example is the version from Wed, 23th Oct 2018.
Project "Twain.rbp"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() t.SelectDS StaticText1.text=str(t.Lasterror) dim i as TwainIdentityMBS = t.DSIdentity if i<>Nil then MsgBox "Selected: "+i.ProductName end if End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() // asynchronously call t.Acquire StaticText1.text=str(t.Lasterror) End EventHandler
End Control
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
End Control
Control CloseTimer Inherits Timer
ControlInstance CloseTimer Inherits Timer
EventHandler Sub Action() DoClose End EventHandler
End Control
Control TransferTimer Inherits Timer
ControlInstance TransferTimer Inherits Timer
EventHandler Sub Action() DoTransfer End EventHandler
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action() dim devices() as TwainIdentityMBS = t.AllDevices dim names() as string for each d as TwainIdentityMBS in devices names.Append d.ProductName+" from "+d.Manufacturer next MsgBox "Found devices: "+Join(names, ", ") End EventHandler
End Control
Control PushButton4 Inherits PushButton
ControlInstance PushButton4 Inherits PushButton
EventHandler Sub Action() dim device as TwainIdentityMBS = t.DSIdentity if device = nil then MsgBox "no device selected." else MsgBox device.ProductName end if End EventHandler
End Control
Control PushButton5 Inherits PushButton
ControlInstance PushButton5 Inherits PushButton
EventHandler Sub Action() dim devices() as TwainIdentityMBS = t.AllDevices dim c as integer = UBound(devices)+1 dim p as TwainIdentityMBS = devices(rnd * c) t.SelectDS(p) if t.Lasterror = 0 then MsgBox "selected device: "+p.ProductName else MsgBox "Failed to select device: "+str(t.Lasterror) end if End EventHandler
End Control
Control PushButton6 Inherits PushButton
ControlInstance PushButton6 Inherits PushButton
EventHandler Sub Action() dim device as TwainIdentityMBS = t.DefaultDevice if device = nil then MsgBox "no device selected." else MsgBox device.ProductName end if End EventHandler
End Control
Control PushButton7 Inherits PushButton
ControlInstance PushButton7 Inherits PushButton
EventHandler Sub Action() dim devices() as TwainIdentityMBS = t.AllDevices dim c as integer = UBound(devices)+1 dim p as TwainIdentityMBS = devices(rnd * c) t.DefaultDevice = p if t.Lasterror = 0 then MsgBox "OK" else MsgBox "Failed to select device: "+str(t.Lasterror) end if End EventHandler
End Control
Control PushButton8 Inherits PushButton
ControlInstance PushButton8 Inherits PushButton
EventHandler Sub Action() dim p as Picture = t.Acquire(false, false) if p<>Nil then Canvas1.Backdrop = p else System.DebugLog "Acquire returned nil picture." end if StaticText1.text=str(t.Lasterror) End EventHandler
End Control
EventHandler Sub Close() if t <> nil then t.win = nil end if 't.RemoveEvent End EventHandler
EventHandler Sub Open() t = new TWAIN(t.TWCY_GERMANY, t.TWLG_GERMAN) t.win = self End EventHandler
Sub DoClose() t.DisableDS t.CloseDS StaticText1.text=str(t.Lasterror) End Sub
Sub DoTransfer() // you can query image info dim img as TwainImageInfoMBS = t.ImageInfo dim n as integer = 1 // now transfer do dim p as Picture=t.TransferImage if p<>Nil then Canvas1.Backdrop = p dim f as FolderItem = SpecialFolder.Desktop.Child("TransferImage"+str(n)+".jpg") p.Save(f, p.SaveAsJPEG) else System.DebugLog "TransferImage returned nil picture." exit end if n = n + 1 System.DebugLog "PendingTransferCount: "+str(t.PendingTransferCount) loop until t.PendingTransferCount < 1 t.DisableDS t.CloseDS StaticText1.text=str(t.Lasterror) End Sub
Property t As TWAIN
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Class TWAIN Inherits TwainMBS
EventHandler Sub CloseRequest() System.DebugLog CurrentMethodName if win <> nil then if win.ControlCount = 0 then // window already closed! win = nil else // start timer to do close win.CloseTimer.Mode = timer.ModeSingle end if end if End EventHandler
EventHandler Sub TransferEnded(pic as picture, ImageInfo as TwainImageInfoMBS, sliced as boolean, layout as TwainImageLayoutMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub TransferProgress(percent as double, dataRead as Int64, DataSize as Int64, ImageInfo as TwainImageInfoMBS, NewDataSize as integer, NewData as Memoryblock, NewPicture as Picture, layout as TwainImageLayoutMBS, Columns as Integer, Rows as Integer, XOffset as Integer, YOffset as Integer) System.DebugLog CurrentMethodName+" "+str(percent) End EventHandler
EventHandler Sub TransferReady() System.DebugLog CurrentMethodName if win <> nil then if win.ControlCount = 0 then // window already closed! win = nil else // start timer to do transfer win.TransferTimer.Mode = timer.ModeSingle end if end if End EventHandler
EventHandler Function TransferStarted(DataSize as Int64, ImageInfo as TwainImageInfoMBS, layout as TwainImageLayoutMBS) As boolean System.DebugLog CurrentMethodName+" "+str(DataSize) End EventHandler
Property win As MainWindow
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS Picture Plugin.




Links
MBS FileMaker blog