Platforms to show: All Mac Windows Linux Cross-Platform

/MacFrameworks/Image Capture/Camera Browser


Required plugins for this example: MBS AVFoundation Plugin, MBS MacCocoa Plugin, MBS MacBase Plugin, MBS Main Plugin, MBS MacCG Plugin, MBS MacCF Plugin, MBS MacControls Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacFrameworks/Image Capture/Camera Browser

This example is the version from Wed, 15th Jul 2014.

Project "Camera Browser.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control List Inherits Listbox
ControlInstance List Inherits Listbox
EventHandler Function CellTextPaint(g As Graphics, row As Integer, column As Integer, x as Integer, y as Integer) As Boolean if column = 0 then dim pic as Picture = me.CellTag(row, column) if pic<>Nil then g.DrawPicture pic, 0, 0, 50, 50, 0, 0, pic.Width, pic.Height Return true end if end if End EventHandler
EventHandler Sub Change() HList.DeleteAllRows FList.DeleteAllRows SyncButton.Enabled = false TakeButton.Enabled = false if me.ListIndex >= 0 then openCamera end if UpdateButtons End EventHandler
End Control
Control tab Inherits TabPanel
ControlInstance tab Inherits TabPanel
End Control
Control HList Inherits Listbox
ControlInstance HList Inherits Listbox
EventHandler Sub Change() UpdateButtons End EventHandler
EventHandler Sub ExpandRow(row As Integer) dim v as Variant = me.RowTag(row) if v isa ICCameraFolderMBS then dim c as ICCameraFolderMBS = v dim items() as ICCameraItemMBS = c.contents for each it as ICCameraItemMBS in items AddItem it next end if End EventHandler
End Control
Control FList Inherits Listbox
ControlInstance FList Inherits Listbox
EventHandler Function CellTextPaint(g As Graphics, row As Integer, column As Integer, x as Integer, y as Integer) As Boolean if column = 0 then dim pic as Picture = me.CellTag(row, column) if pic<>Nil then g.DrawPicture pic, 0, 0, 50, 50, 0, 0, pic.Width, pic.Height Return true end if end if End EventHandler
EventHandler Sub Change() UpdateButtons End EventHandler
End Control
Control SyncButton Inherits PushButton
ControlInstance SyncButton Inherits PushButton
EventHandler Sub Action() dim camera as ICCameraDeviceMBS = selectedCamera if camera<>nil then camera.requestSyncClock end if End EventHandler
End Control
Control TakeButton Inherits PushButton
ControlInstance TakeButton Inherits PushButton
EventHandler Sub Action() dim camera as ICCameraDeviceMBS = selectedCamera if camera<>nil then camera.requestTakePicture end if End EventHandler
End Control
Control DownloadButton Inherits PushButton
ControlInstance DownloadButton Inherits PushButton
EventHandler Sub Action() downloadFiles SelectedFiles End EventHandler
End Control
Control DeleteButton Inherits PushButton
ControlInstance DeleteButton Inherits PushButton
EventHandler Sub Action() deletefiles SelectedFiles End EventHandler
End Control
Control ReadButton Inherits PushButton
ControlInstance ReadButton Inherits PushButton
EventHandler Sub Action() readFiles SelectedFiles End EventHandler
End Control
EventHandler Sub Open() events = new MyImageCaptureEvents DeviceBrowser = new ICDeviceBrowserMBS DeviceBrowser.browsedDeviceTypeMask = Bitwise.BitOr(ICDeviceMBS.ICDeviceLocationTypeMaskLocal, ICDeviceMBS.ICDeviceLocationTypeMaskRemote, ICDeviceMBS.ICDeviceTypeMaskCamera) DeviceBrowser.start FList.ColumnAlignment(2) = Listbox.AlignRight FList.ColumnAlignment(3) = Listbox.AlignRight FList.ColumnAlignment(4) = Listbox.AlignRight FList.ColumnAlignment(5) = Listbox.AlignRight HList.ColumnAlignment(2) = Listbox.AlignRight HList.ColumnAlignment(3) = Listbox.AlignRight HList.ColumnAlignment(4) = Listbox.AlignRight HList.ColumnAlignment(5) = Listbox.AlignRight End EventHandler
Sub AddDevice(camera as ICCameraDeviceMBS) Cameras.Append camera List.AddRow "", camera.Name List.RowTag(List.LastIndex) = camera dim image as CGImageMBS = camera.Icon dim pic as Picture = image.Picture List.CellTag(List.LastIndex,0) = pic End Sub
Sub AddItem(it as ICCameraItemMBS) if it isa ICCameraFolderMBS then dim f as ICCameraFolderMBS = ICCameraFolderMBS(it) dim c as integer = f.contents.Ubound+1 dim size as string = str(c)+" items" if c = 1 then size = "one item" HList.AddFolder "" HList.Cell(HList.LastIndex,1) = f.Name HList.Cell(HList.LastIndex,3) = size HList.RowTag(HList.LastIndex) = f ShowMetaData HList, HList.LastIndex, f ShowThumbnail HList, HList.LastIndex, f elseif it isa ICCameraFileMBS then dim f as ICCameraFileMBS = ICCameraFileMBS(it) dim size as string = str(f.FileSize/1024,"-0")+" KB" HList.AddRow "", f.Name, "", size HList.RowTag(HList.LastIndex) = f ShowThumbnail HList, HList.LastIndex, f ShowMetaData HList, HList.LastIndex, f end if End Sub
Sub CheckCamera() dim camera as ICCameraDeviceMBS = selectedCamera SyncButton.Enabled = Camera.canSyncClock TakeButton.Enabled = Camera.canTakePicture dim files() as ICCameraFileMBS = camera.mediaFiles for each f as ICCameraFileMBS in files dim size as string = str(f.FileSize/1024,"-0")+" KB" FList.AddRow "", f.Name, "", size FList.RowTag(FList.LastIndex) = f ShowMetaData FList, FList.LastIndex, f ShowThumbnail FList, FList.LastIndex, f next dim items() as ICCameraItemMBS = camera.contents for each it as ICCameraItemMBS in items AddItem it next End Sub
Function SelectedFiles() As ICCameraFileMBS() dim files() as ICCameraFileMBS if Tab.Value = 0 then dim u as integer = FList.ListCount-1 for i as integer = 0 to u if FList.Selected(i) then files.Append FList.RowTag(i) end if next else dim u as integer = HList.ListCount-1 for i as integer = 0 to u if HList.Selected(i) then files.Append HList.RowTag(i) end if next end if Return files End Function
Sub ShowMetaData(list as listbox, row as integer, f as ICCameraItemMBS) dim d as Dictionary = f.MetadataIfAvailable if d<>Nil then dim make as string dim model as string dim width as string dim height as string dim datum as string dim Exif as Dictionary = d.Lookup("{Exif}", nil) dim Tiff as Dictionary = d.Lookup("{TIFF}", nil) If Tiff<>nil then make = tiff.Lookup("Make", "") model = tiff.Lookup("Model", "") end if If Exif<>nil then datum = Exif.Lookup("DateTimeOriginal", "") width = Exif.Lookup("PixelWidth", "") height = Exif.Lookup("PixelHeight", "") end if List.Cell(row,2) = datum List.Cell(row,4) = Width List.Cell(row,5) = height List.Cell(row,6) = make List.Cell(row,7) = model end if End Sub
Sub ShowThumbnail(list as listbox, row as integer, f as ICCameraItemMBS) dim image as CGImageMBS = f.thumbnailIfAvailable if image<>nil then dim pic as Picture = image.Picture if pic<>Nil then if FList = list then list.CellTag(row,0) = pic elseif list = HList then list.RowPicture(row) = pic.ProportinalScaled(16,16) end if end if end if End Sub
Sub UpdateButtons() dim l as listbox if tab.Value = 0 then l = FList else l = HList end if if l.SelCount > 0 then DownloadButton.Enabled = true ReadButton.Enabled = true DeleteButton.Enabled = true else DownloadButton.Enabled = false ReadButton.Enabled = false DeleteButton.Enabled = false end if End Sub
Function canDelete() As Boolean dim files() as ICCameraFileMBS = SelectedFiles for each f as ICCameraFileMBS in files if not f.locked then Return true end if next End Function
Function canDownload() As Boolean if HList.SelCount > 0 or FList.SelCount > 0 then Return true end if End Function
Sub deletefiles(files() as ICCameraFileMBS) dim camera as ICCameraDeviceMBS = selectedCamera camera.requestDeleteFiles files End Sub
Sub didReceiveMetadataForItem(item as ICCameraItemMBS) // got metadata or thumbnail dim u as integer = fList.ListCount-1 for i as integer = 0 to u dim f as ICCameraItemMBS = fList.RowTag(i) if f = item then ShowMetaData FList, i, f end if next u = hList.ListCount-1 for i as integer = 0 to u dim f as ICCameraItemMBS = hList.RowTag(i) if f = item then ShowMetaData FList, i, f end if next End Sub
Sub didReceiveThumbnailForItem(item as ICCameraItemMBS) // got metadata or thumbnail dim u as integer = fList.ListCount-1 for i as integer = 0 to u dim f as ICCameraItemMBS = fList.RowTag(i) if f = item then ShowThumbnail FList, i, f end if next u = hList.ListCount-1 for i as integer = 0 to u dim f as ICCameraItemMBS = hList.RowTag(i) if f = item then ShowThumbnail FList, i, f end if next End Sub
Sub didRemoveDevice(d as ICDeviceMBS) dim u as integer = List.ListCount-1 for i as integer = 0 to u if list.RowTag(i) = d then List.RemoveRow i end if next End Sub
Sub didRemoveItems(items() as ICCameraItemMBS) // remove items from both lists dim u as integer = FList.ListCount-1 for i as integer = u downto 0 dim v as Variant = Flist.RowTag(i) if items.IndexOf(v) >= 0 then FList.RemoveRow i end if next u = HList.ListCount-1 for i as integer = u downto 0 dim v as Variant = HList.RowTag(i) if items.IndexOf(v) >= 0 then HList.RemoveRow i end if next End Sub
Sub downloadFiles(files() as ICCameraFileMBS) dim options as new Dictionary dim cfurl as CFURLMBS = NewCFURLMBSFile(SpecialFolder.Desktop) options.Value(ICCameraDeviceMBS.ICDownloadsDirectoryURL) = cfurl for each f as ICCameraFileMBS in files dim d as ICDeviceMBS = f.Device if d isa ICCameraDeviceMBS then dim c as ICCameraDeviceMBS = ICCameraDeviceMBS(d) c.requestDownloadFile f, options end if next End Sub
Sub openCamera() dim camera as ICCameraDeviceMBS = selectedCamera if camera<>Nil then camera.requestOpenSession end if End Sub
Sub readFiles(files() as ICCameraFileMBS) for each f as ICCameraFileMBS in files dim d as ICDeviceMBS = f.Device if d isa ICCameraDeviceMBS then dim c as ICCameraDeviceMBS = ICCameraDeviceMBS(d) c.requestReadDataFromFile f, 0, f.fileSize end if next End Sub
Function selectedCamera() As ICCameraDeviceMBS if List.ListIndex >= 0 then Return List.RowTag(List.ListIndex) end if End Function
Note "Untitled"
Property Cameras() As ICCameraDeviceMBS
Property DeviceBrowser As ICDeviceBrowserMBS
Property events As MyImageCaptureEvents
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 MyImageCaptureEvents Inherits ImageCaptureEventsMBS
EventHandler Sub cameraDeviceDidAddItem(camera as ICCameraDeviceMBS, item as ICCameraItemMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub cameraDeviceDidAddItems(camera as ICCameraDeviceMBS, items() as ICCameraItemMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub cameraDeviceDidBecomeReadyWithCompleteContentCatalog(camera as ICCameraDeviceMBS) System.DebugLog CurrentMethodName MainWindow.CheckCamera End EventHandler
EventHandler Sub cameraDeviceDidChangeCapability(camera as ICCameraDeviceMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub cameraDeviceDidCompleteDeleteFilesWithError(camera as ICCameraDeviceMBS, error as NSErrorMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub cameraDeviceDidDownloadFile(file as ICCameraFileMBS, error as NSErrorMBS, options as Dictionary, device as ICCameraDeviceMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub cameraDeviceDidReadData(data as Memoryblock, file as ICCameraFileMBS, error as NSErrorMBS, device as ICCameraDeviceMBS) System.DebugLog CurrentMethodName dim f as FolderItem = SpecialFolder.Desktop.Child(file.Name) dim b as BinaryStream = BinaryStream.Create(f) b.Write data End EventHandler
EventHandler Sub cameraDeviceDidReceiveDownloadProgressForFile(file as ICCameraFileMBS, downloadedBytes as UInt64, maxBytes as UInt64) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub cameraDeviceDidReceiveMetadataForItem(camera as ICCameraDeviceMBS, item as ICCameraItemMBS) System.DebugLog CurrentMethodName MainWindow.didReceiveMetadataForItem item End EventHandler
EventHandler Sub cameraDeviceDidReceivePTPEvent(camera as ICCameraDeviceMBS, eventData as MemoryBlock) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub cameraDeviceDidReceiveThumbnailForItem(camera as ICCameraDeviceMBS, item as ICCameraItemMBS) System.DebugLog CurrentMethodName MainWindow.didReceiveThumbnailForItem item End EventHandler
EventHandler Sub cameraDeviceDidRemoveItem(camera as ICCameraDeviceMBS, item as ICCameraItemMBS) System.DebugLog CurrentMethodName MainWindow.didRemoveItems array(item) End EventHandler
EventHandler Sub cameraDeviceDidRemoveItems(camera as ICCameraDeviceMBS, items() as ICCameraItemMBS) System.DebugLog CurrentMethodName MainWindow.didRemoveItems items End EventHandler
EventHandler Sub cameraDeviceDidRenameItems(camera as ICCameraDeviceMBS, items() as ICCameraItemMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub cameraDeviceDidSendPTPCommand(command as Memoryblock, data as Memoryblock, response as MemoryBlock, error as NSErrorMBS, device as ICCameraDeviceMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub cameraDeviceDidUploadFile(fileURL as string, file as FolderItem, error as NSErrorMBS, device as ICCameraDeviceMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub deviceBrowserDeviceDidChangeName(browser as ICDeviceBrowserMBS, device as ICDeviceMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub deviceBrowserDeviceDidChangeSharingState(browser as ICDeviceBrowserMBS, device as ICDeviceMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub deviceBrowserDidAddDevice(browser as ICDeviceBrowserMBS, device as ICDeviceMBS, moreComing as boolean) System.DebugLog CurrentMethodName if BitwiseAnd(device.type, device.ICDeviceTypeMaskCamera) = device.ICDeviceTypeMaskCamera then MainWindow.AddDevice ICCameraDeviceMBS(device) end if End EventHandler
EventHandler Sub deviceBrowserDidEnumerateLocalDevices(browser as ICDeviceBrowserMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub deviceBrowserDidRemoveDevice(browser as ICDeviceBrowserMBS, device as ICDeviceMBS, moreGoing as boolean) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub deviceBrowserRequestsSelectDevice(browser as ICDeviceBrowserMBS, device as ICDeviceMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub deviceDidBecomeReady(device as ICDeviceMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub deviceDidChangeName(device as ICDeviceMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub deviceDidChangeSharingState(device as ICDeviceMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub deviceDidCloseSessionWithError(device as ICDeviceMBS, error as NSErrorMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub deviceDidEncounterError(device as ICDeviceMBS, error as NSErrorMBS) System.DebugLog CurrentMethodName MsgBox error.LocalizedDescription End EventHandler
EventHandler Sub deviceDidOpenSessionWithError(device as ICDeviceMBS, error as NSErrorMBS) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub deviceDidReceiveButtonPress(device as ICDeviceMBS, buttonType as String) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub deviceDidReceiveCustomNotification(device as ICDeviceMBS, notification as Dictionary, data as Memoryblock) System.DebugLog CurrentMethodName End EventHandler
EventHandler Sub deviceDidReceiveStatusInformation(device as ICDeviceMBS, status as Dictionary) System.DebugLog CurrentMethodName 'MainWindow.didReceiveStatusInformation Status End EventHandler
EventHandler Sub deviceDidRemove(device as ICDeviceMBS) System.DebugLog CurrentMethodName MainWindow.didRemoveDevice device End EventHandler
EventHandler Sub deviceDidSendMessage(messageCode as UInt32, data as Memoryblock, error as NSErrorMBS, device as ICDeviceMBS) System.DebugLog CurrentMethodName End EventHandler
End Class
Module UtilModule
Sub AddRow(extends p as PopupMenu, text as string, tag as Variant) p.AddRow text p.RowTag(p.ListCount-1) = tag End Sub
Function ProportinalScaled(extends pic as Picture, Width as integer, Height as Integer) As Picture // Calculate scale factor dim faktor as Double = min( Height / Pic.Height, Width / Pic.Width) // Calculate new size dim w as integer = Pic.Width * faktor dim h as integer = Pic.Height * faktor // create new picture dim NewPic as new Picture(w,h,32) // draw picture in the new size NewPic.Graphics.DrawPicture Pic, 0, 0, w, h, 0, 0, Pic.Width, Pic.Height // return result Return NewPic End Function
End Module
FileTypes1
Filetype image/jpeg
End FileTypes1
End Project

See also:

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


The biggest plugin in space...