Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS Barcode Plugin
Last modified Sun, 5th Nov 2022.
You find this example project in your MBS Xojo Plugin download as a Xojo project file within the examples folder: /Barcode/zbar
Download this example: zbar.zip
Project "zbar.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub NewDocument()
#If DebugBuild Then
Dim f As FolderItem = GetFolderItem("test.png")
OpenDocument f
#else
Dim f As FolderItem = GetOpenFolderItem(FileTypes1.All)
If f <> Nil Then
OpenDocument f
End If
#EndIf
End EventHandler
EventHandler Sub Open()
#If TargetMacOS Then
Const libname = "libzbar.0.dylib"
Dim LibFile As FolderItem = GetFolderItem(libname)
If ZBarMBS.LoadLibrary(LibFile) Then
'MsgBox "ZBar loaded."
Else
MsgBox "Failed to load ZBar library: "+ZBarMBS.LibraryLoadErrorMessage
End If
#ElseIf TargetLinux Then
Const libname = "libzbar.so.0"
// /usr/lib/x86_64-linux-gnu/libzbar.so.0
If ZBarMBS.LoadLibrary(libname) Then
'MsgBox "ZBar loaded."
Else
MsgBox "Failed to load ZBar library: "+ZBarMBS.LibraryLoadErrorMessage
End If
#elseif TargetWindows then
Const libname = "libzbar.dll"
If ZBarMBS.LoadLibrary(libname) Then
'MsgBox "ZBar loaded."
Else
MsgBox "Failed to load ZBar library: "+ZBarMBS.LibraryLoadErrorMessage
End If
#Else
#Pragma error unknown platform?
#EndIf
End EventHandler
EventHandler Sub OpenDocument(item As FolderItem)
scan item
End EventHandler
Function FileOpen() As Boolean
Dim f As FolderItem = GetOpenFolderItem(FileTypes1.All)
If f <> Nil Then
OpenDocument f
End If
Return True
End Function
Sub scan(file as FolderItem)
Dim p As Picture = Picture.Open(file)
If p <> Nil Then
Dim symbols() As ZBarMBS = ZBarMBS.Scan(p)
For Each symbol As ZBarMBS In symbols
Dim m As New MainWindow
Dim s As String = symbol.Name+": "+symbol.Text+" "+Str(symbol.Quality)
m.InfoLabel.Text = s
m.pic = p
Next
End If
End Sub
End Class
Class MainWindow Inherits Window
Control Out Inherits Canvas
ControlInstance Out Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect)
If pic <> Nil Then
Dim faktor As Double = Min( g.Height / Pic.Height, g.Width / Pic.Width)
// Calculate new size
Dim w As Integer = Pic.Width * faktor
Dim h As Integer = Pic.Height * faktor
// draw picture in the new size
g.DrawPicture Pic, 0, 0, w, h, 0, 0, Pic.Width, Pic.Height
End If
End EventHandler
End Control
Control InfoLabel Inherits Label
ControlInstance InfoLabel Inherits Label
End Control
Property pic As Picture
End Class
FileTypes1
Filetype Jpeg
Filetype Png
End FileTypes1
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileOpen = "Open..."
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
Sign
End Sign
End Project
Download this example: zbar.zip
The items on this page are in the following plugins: MBS Barcode Plugin.