Platforms to show: All Mac Windows Linux Cross-Platform
/Barcode/zxing/Multi Barcode Tests/Multi Barcode Tests
Required plugins for this example: MBS Barcode Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Barcode/zxing/Multi Barcode Tests/Multi Barcode Tests
This example is the version from Mon, 27th Oct 2019.
Project "Multi Barcode Tests.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MultiBarcodeWindow Inherits Window
Control Image Inherits Canvas
ControlInstance Image Inherits Canvas
End Control
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
Control ByQuadrantReaderButton Inherits PushButton
ControlInstance ByQuadrantReaderButton Inherits PushButton
EventHandler Sub Action()
List.DeleteAllRows
Dim f As FolderItem = FindFile("qrcodes.jpg")
Dim p As Picture = Picture.Open(f)
image.Backdrop = p
pic = p
// this will try quadrants and find it in first quadrant
Dim QRCodeReader As New zxingQRCodeReaderMBS
Dim ByQuadrantReader As New zxingByQuadrantReaderMBS(QRCodeReader)
Dim Bitmap As zxingBinaryBitmapMBS = zxingBinaryBitmapMBS.CreateWithPicture(pic)
Dim result As zxingResultMBS = ByQuadrantReader.decode(Bitmap)
List.AddRow result.BarcodeFormat.Name
List.AddRow result.Text
// try another code here with cropped image
Dim Bitmap2 As zxingBinaryBitmapMBS = Bitmap.crop(200, 200, 200, 200)
Dim result2 As zxingResultMBS = QRCodeReader.decode(Bitmap2)
List.AddRow result2.BarcodeFormat.Name
List.AddRow result2.Text
// try another code here with cropped image
Dim Bitmap3 As zxingBinaryBitmapMBS = Bitmap.crop(0, 200, 200, 200)
Dim result3 As zxingResultMBS = QRCodeReader.decode(Bitmap3)
List.AddRow result3.BarcodeFormat.Name
List.AddRow result3.Text
// try another code here with cropped image
Dim Bitmap4 As zxingBinaryBitmapMBS = Bitmap.crop(200, 0, 200, 200)
Dim result4 As zxingResultMBS = QRCodeReader.decode(Bitmap4)
List.AddRow result4.BarcodeFormat.Name
List.AddRow result4.Text
Exception r As zxingExceptionMBS
MsgBox r.message
End EventHandler
End Control
Control MultipleBarcodeReaderButton Inherits PushButton
ControlInstance MultipleBarcodeReaderButton Inherits PushButton
EventHandler Sub Action()
List.DeleteAllRows
Dim f As FolderItem = FindFile("qrcodes4.jpg")
Dim p As Picture = Picture.Open(f)
image.Backdrop = p
pic = p
// a couple of barcode readers may not work if two barcodes are horizontally close to each other
// so we try vertical ones here
Dim hint As New zxingDecodeHintsMBS(zxingDecodeHintsMBS.QR_CODE_HINT)
Dim QRCodeReader As New zxingQRCodeReaderMBS
Dim MultipleBarcodeReader As New zxingGenericMultipleBarcodeReaderMBS(QRCodeReader)
Dim Bitmap As zxingBinaryBitmapMBS = zxingBinaryBitmapMBS.CreateWithPicture(pic)
Dim results() As zxingResultMBS = MultipleBarcodeReader.decodeMultiple(bitmap, hint)
For Each r As zxingResultMBS In results
List.AddRow r.BarcodeFormat.Name
List.AddRow r.Text
Next
Exception r As zxingExceptionMBS
MsgBox r.message
End EventHandler
End Control
EventHandler Sub Open()
Dim f As FolderItem = FindFile("qrcodes.jpg")
Dim p As Picture = Picture.Open(f)
image.Backdrop = p
pic = p
End EventHandler
Function FindFile(name as string) As FolderItem
// Look for file in parent folders from executable on
dim parent as FolderItem = app.ExecutableFile.Parent
while parent<>Nil
dim file as FolderItem = parent.Child(name)
if file<>Nil and file.Exists then
Return file
end if
parent = parent.Parent
wend
End Function
Property pic As Picture
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project
See also:
The items on this page are in the following plugins: MBS Barcode Plugin.