Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS Images Plugin, MBS MacOSX Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacOSX/Image Capture
This example is the version from Mon, 18th Mar 2012.
Project "Image Capture.xojo_binary_project"
Class MainWindow Inherits Window
Control Tab Inherits TabPanel
ControlInstance Tab Inherits TabPanel
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
RefreshDeviceList
End EventHandler
End Control
Control DeviceListbox Inherits ListBox
ControlInstance DeviceListbox Inherits ListBox
EventHandler Sub ExpandRow(row As Integer)
ExpandList row, me
End EventHandler
End Control
Control PushButton4 Inherits PushButton
ControlInstance PushButton4 Inherits PushButton
EventHandler Sub Action()
Import
End EventHandler
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control EventListbox Inherits ListBox
ControlInstance EventListbox Inherits ListBox
EventHandler Sub ExpandRow(row As Integer)
ExpandList row, me
End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action()
EventListbox.DeleteAllRows
End EventHandler
End Control
Control DevicePopup Inherits PopupMenu
ControlInstance DevicePopup Inherits PopupMenu
EventHandler Sub Change()
if me.ListIndex>=0 then
PushShowData.Enabled = True
PushShowtree.Enabled = True
ImportButton.Enabled = true
else
PushShowData.Enabled = false
PushShowtree.Enabled = false
ImportButton.Enabled = false
end if
End EventHandler
End Control
Control PushShowTree Inherits PushButton
ControlInstance PushShowTree Inherits PushButton
EventHandler Sub Action()
ShowFiles "tree"
End EventHandler
End Control
Control PushShowData Inherits PushButton
ControlInstance PushShowData Inherits PushButton
EventHandler Sub Action()
ShowFiles "data"
End EventHandler
End Control
Control TreeListbox Inherits ListBox
ControlInstance TreeListbox Inherits ListBox
EventHandler Sub Change()
if me.ListIndex<0 then
ThumbnailButton.Enabled = false
PictureButton.Enabled = False
else
dim v as Variant = me.CellTag(me.ListIndex,0)
if v isa ImageCaptureObjectMBS then
ThumbnailButton.Enabled = true
PictureButton.Enabled = true
else
ThumbnailButton.Enabled = false
PictureButton.Enabled = false
end if
end if
End EventHandler
EventHandler Sub ExpandRow(row As Integer)
ExpandList row, me
End EventHandler
End Control
Control ThumbnailButton Inherits PushButton
ControlInstance ThumbnailButton Inherits PushButton
EventHandler Sub Action()
dim v as Variant = TreeListbox.CellTag(TreeListbox.ListIndex,0)
if v isa ImageCaptureObjectMBS then
dim o as ImageCaptureObjectMBS = v
dim data as string = o.CopyThumbnail(o.kICAThumbnailFormatJPEG)
if lenb(data)>0 then
ShowPicture data, o.PropertyDictionary.Lookup(o.kICAPropertyImageFilename,"?")
end if
if o.Lasterror<>0 then
MsgBox "Lasterror: "+str(o.Lasterror)
end if
end if
End EventHandler
End Control
Control PictureButton Inherits PushButton
ControlInstance PictureButton Inherits PushButton
EventHandler Sub Action()
dim v as Variant = TreeListbox.CellTag(TreeListbox.ListIndex,0)
if v isa ImageCaptureObjectMBS then
dim o as ImageCaptureObjectMBS = v
dim d as Dictionary = o.PropertyDictionary
dim size as integer = d.Value(o.kICAPropertyImageSize)
dim data as string = o.CopyData(0, size)
if lenb(data)>0 then
ShowPicture data, d.Lookup(o.kICAPropertyImageFilename,"?")
end if
if o.Lasterror<>0 then
MsgBox "Lasterror: "+str(o.Lasterror)
end if
end if
End EventHandler
End Control
Control ImportButton Inherits PushButton
ControlInstance ImportButton Inherits PushButton
EventHandler Sub Action()
ImportAllPictures
End EventHandler
End Control
EventHandler Sub Open()
m = new MyImageCapture
RegisterEvents
RefreshDeviceList
End EventHandler
Sub ExpandList(row as integer, liste as listbox)
dim o as Variant = liste.CellTag(row,0)
if o isa ImageCaptureObjectMBS then
dim c as ImageCaptureObjectMBS = o
dim d as Dictionary = c.PropertyDictionary
liste.Addfolder "Properties"
Liste.Celltag(liste.LastIndex,0)=d
elseif o isa Dictionary then
dim p as Dictionary = o
for each key as Variant in p.keys
dim v as Variant = p.Value(key)
if key = "icao" then
if handle <> 0 then
dim co as new ImageCaptureObjectMBS(v)
liste.AddFolder key
Liste.Cell(liste.LastIndex,1)=v
Liste.CellTag(liste.LastIndex,0)=co
else
liste.AddRow key.StringValue
Liste.Cell(liste.LastIndex,1)=v
end if
elseif v.IsArray then
liste.Addfolder key
Liste.Celltag(liste.LastIndex,0)=v
elseif v isa Dictionary then
liste.Addfolder key
Liste.Celltag(liste.LastIndex,0)=v
else
liste.AddRow key.StringValue
Liste.Cell(liste.LastIndex,1)=v
end if
next
elseif o.IsArray then
dim a(-1) as Variant = o
for each v as Variant in a
if v.IsArray then
liste.Addfolder "array"
Liste.Celltag(liste.LastIndex,0)=v
elseif v isa Dictionary then
liste.Addfolder "dictionary"
Liste.Celltag(liste.LastIndex,0)=v
else
liste.AddRow "value"
Liste.Cell(liste.LastIndex,1)=v
end if
next
end if
End Sub
Sub Import()
dim flags as integer = ImageCaptureObjectMBS.kICAAllowMultipleImages
dim types(-1) as string
types.Append "tif"
types.Append "tiff"
types.Append "jpg"
types.Append "png"
dim files(-1) as string = m.ImportImage(flags, types)
for each data as string in files
ShowPicture data, "?"
next
End Sub
Sub ImportAllPictures()
// get device
dim deviceHandle as integer = DevicePopup.RowTag(DevicePopup.ListIndex)
dim deviceObject as new ImageCaptureObjectMBS(deviceHandle)
// now import
dim d1 as Dictionary = deviceObject.PropertyDictionary
if d1<>nil then
dim items(-1) as Variant = d1.Value("data")
for each item as Dictionary in items
dim handle as integer = item.Value("icao")
dim o as new ImageCaptureObjectMBS(handle)
dim d2 as Dictionary = o.PropertyDictionary
dim size as integer = d2.Value(o.kICAPropertyImageSize)
dim data as string = o.CopyData(0, size)
if lenb(data)>0 then
ShowPicture data, d2.Lookup(o.kICAPropertyImageFilename,"?")
end if
if o.Lasterror<>0 then
MsgBox "Lasterror: "+str(o.Lasterror)
end if
next
end if
End Sub
Sub RefreshDeviceList()
DeviceListbox.deleteAllRows
DevicePopup.DeleteAllRows
// get the list object
dim list as ImageCaptureObjectMBS = m.DeviceList
if List<>Nil then
// look into properties
dim dic as Dictionary = list.PropertyDictionary
// take the devices array there
if dic<>Nil and dic.HasKey(ImageCaptureObjectMBS.kICADevicesArrayKey) then
dim a(-1) as Variant = dic.Value(ImageCaptureObjectMBS.kICADevicesArrayKey)
// add each Device to device listbox
for each properties as Dictionary in a
dim name as string = Properties.Value("ifil")
DeviceListbox.Addfolder name
DeviceListbox.Celltag(DeviceListbox.LastIndex,0)=properties
DeviceListbox.Expanded(DeviceListbox.LastIndex)=true
// and to the Device popupmenu
dim handle as integer = properties.Value("icao")
DevicePopup.AddRow name
DevicePopup.RowTag(DevicePopup.ListCount-1)=handle
next
end if
end if
if DevicePopup.ListCount>=0 then
DevicePopup.ListIndex=-1
end if
End Sub
Sub RegisterEvents()
dim events(-1) as string
events.Append m.kICANotificationTypeObjectAdded
events.Append m.kICANotificationTypeObjectRemoved
events.Append m.kICANotificationTypeObjectInfoChanged
events.Append m.kICANotificationTypeStoreAdded
events.Append m.kICANotificationTypeStoreRemoved
events.Append m.kICANotificationTypeStoreFull
events.Append m.kICANotificationTypeStoreInfoChanged
events.Append m.kICANotificationTypeDeviceAdded
events.Append m.kICANotificationTypeDeviceRemoved
events.Append m.kICANotificationTypeDeviceInfoChanged
events.Append m.kICANotificationTypeDevicePropertyChanged
events.Append m.kICANotificationTypeDeviceWasReset
events.Append m.kICANotificationTypeDeviceStatusInfo
events.Append m.kICANotificationTypeDeviceStatusError
events.Append m.kICANotificationTypeCaptureComplete
events.Append m.kICANotificationTypeRequestObjectTransfer
events.Append m.kICANotificationTypeTransactionCanceled
events.Append m.kICANotificationTypeUnreportedStatus
events.Append m.kICANotificationTypeProprietary
events.Append m.kICANotificationTypeDeviceConnectionProgress
events.Append m.kICANotificationTypeDownloadProgressStatus
events.Append m.kICANotificationTypeScanProgressStatus
events.Append m.kICANotificationTypeScannerSessionClosed
events.Append m.kICANotificationTypeScannerScanDone
events.Append m.kICANotificationTypeScannerPageDone
events.Append m.kICANotificationTypeScannerButtonPressed
events.Append m.kICANotificationTypeScannerOverviewOverlayAvailable
m.RegisterForEventNotification(nil, events ,nil)
End Sub
Sub ShowFiles(kind as string)
dim deviceHandle as integer = DevicePopup.RowTag(DevicePopup.ListIndex)
dim deviceObject as new ImageCaptureObjectMBS(deviceHandle)
dim d1 as Dictionary = deviceObject.PropertyDictionary
if d1<>nil then
TreeListbox.AddFolder d1.Value("ifil")
TreeListbox.CellTag(TreeListbox.LastIndex,0)=d1.Value(kind)
end if
End Sub
Sub ShowPicture(data as string, title as string)
// We try different functions to get the picture from a video
dim p as Picture= JPEGStringToPictureMBS(data, true)
if p = nil then
p = TIFFStringToPictureMBS(data)
if p=nil then
p = PNGStringToPictureMBS(data,0)
end if
end if
if p<>Nil then
dim pw as new PicWindow
pw.Backdrop = p
pw.Title = Title
pw.Show
else
MsgBox "Failed to decode picture."
end if
End Sub
Property m As MyImageCapture
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileClose = "Close"
MenuItem UntitledSeparator = "-"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
End Class
Class MyImageCapture Inherits ImageCaptureMBS
EventHandler Sub Notification(notificationType as string, notificationDictionary as dictionary)
MainWindow.EventListbox.AddFolder notificationType
MainWindow.EventListbox.Celltag(MainWindow.EventListbox.LastIndex,0)=notificationDictionary
MainWindow.tab.Value = 1
End EventHandler
End Class
Class PicWindow Inherits Window
Function FileClose() As Boolean
close
Return True
End Function
End Class
End Project
See also:
The items on this page are in the following plugins: MBS MacOSX Plugin.