Platforms to show: All Mac Windows Linux Cross-Platform

/Picture/Twain/Twain Sliced


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 Sliced

This example is the version from Wed, 23th Oct 2018.

Project "Twain Sliced.xojo_binary_project"
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() dim p as Picture=t.Acquire StaticText1.text=str(t.Lasterror) if p<>Nil then Canvas1.Backdrop = p dim f as FolderItem = SpecialFolder.Desktop.Child("Acquire.jpg") p.Save(f, p.SaveAsJPEG) else System.DebugLog "Acquire returned nil picture." if t.Lasterror = 0 then t.ProcessEvents end if end if 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
EventHandler Sub Close() 't.RemoveEvent if t <> nil then t.win = nil end if End EventHandler
EventHandler Sub Open() t=new TWAIN(t.TWCY_GERMANY, t.TWLG_GERMAN) t.Parent = self 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 t.ProvideSlicePicture = true t.ProvideSliceData = true // now transfer dim p as Picture=t.TransferImage if p<>Nil then Canvas1.Backdrop = p dim f as FolderItem = SpecialFolder.Desktop.Child("TransferImage.jpg") p.Save(f, p.SaveAsJPEG) else System.DebugLog "TransferImage returned nil picture." end if t.DisableDS t.CloseDS StaticText1.text=str(t.Lasterror) End Sub
Property n As Integer
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) MainWindow.Canvas1.Backdrop = NewPicture count = count + 1 if NewPicture <> Nil then dim f as FolderItem = SpecialFolder.Desktop.Child("TransferImage "+str(count)+".jpg") NewPicture.Save(f, NewPicture.SaveAsJPEG) end if if NewData <> Nil then dim f as FolderItem = SpecialFolder.Desktop.Child("TransferImage "+str(count)+".dat") dim b as BinaryStream = BinaryStream.Create(f, true) b.Write NewData.StringValue(0, NewDataSize) b.Close end if 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) // you can decide here if you want to use slices only // Return true to not get a big picture on the end // if data for image can't be allocated you get sliced automatically. if ImageInfo.ImageWidth > 5000 or ImageInfo.ImageLength > 5000 then System.DebugLog "Image to large, so we use slices." Return true end if if DataSize > 100000000 then // no images over 100 MB in one chunk System.DebugLog "Image to big, so we use slices." Return true end if End EventHandler
Property Win As MainWindow
Property count As Integer
End Class
End Project

See also:

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


The biggest plugin in space...