Platforms to show: All Mac Windows Linux Cross-Platform

/iOS/Photo Picker Desktop


You find this example project in your Plugins Download as a Xojo project file within the examples folder: /iOS/Photo Picker Desktop

This example is the version from Sat, 24th Mar 2023.

Project "Photo Picker Desktop.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control PickButton Inherits PushButton
ControlInstance PickButton Inherits PushButton
EventHandler Sub Action() Dim configuration As New PHPickerConfigurationMBS configuration.Filter = PHPickerFilterMBS.imagesFilter // set to zero for unlimited configuration.SelectionLimit = 1 configuration.Selection = configuration.SelectionDefault configuration.PreferredAssetRepresentationMode = configuration.AssetRepresentationModeCompatible picker = New PHPickerViewController(configuration) picker.ParentWindow = Self picker.Present End EventHandler
End Control
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 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
Sub LoadFileRepresentationCompleted(File as FolderItem, error as NSErrorMBS, result as PHPickerResultMBS) System.DebugLog CurrentMethodName if error <> nil then MessageBox error.LocalizedDescription end if if file <> nil then System.DebugLog file.NativePath // normal opening #if MBS.HasMacCIPlugin = false then // load directly. Picture may be rotated pic = Picture.Open(file) Canvas1.Refresh #else // use CIImage to rotate to always be top left orientation Dim ciImage As CIImageMBS = New CIImageMBS(file) Dim properties As Dictionary = ciImage.properties If properties.HasKey("Orientation") Then Dim orientation As Integer = ciImage.properties.Value("Orientation") ciImage = ciImage.imageByApplyingOrientation(orientation) End If Dim cgPic As CGImageMBS = ciImage.CreateCGImage pic = cgPic.Picture Canvas1.Refresh #endif end if End Sub
Sub PickerFinished(results() as PHPickerResultMBS) System.DebugLog CurrentMethodName self.Results = results if results.Count = 0 then Return dim result as PHPickerResultMBS = results(0) Dim registeredTypeIdentifiers() As String = result.TypeIdentifiers System.DebugLog "Types: "+String.FromArray(registeredTypeIdentifiers, EndOfLine) // HEIC available? if registeredTypeIdentifiers.IndexOf("public.heic") >= 0 then result.loadFileRepresentationForTypeIdentifier("public.heic", WeakAddressOf LoadFileRepresentationCompleted) elseif registeredTypeIdentifiers.IndexOf("public.png") >= 0 then // try png const identifier = "public.png" result.loadFileRepresentationForTypeIdentifier(identifier, WeakAddressOf LoadFileRepresentationCompleted) else // try jpeg const identifier = "public.jpeg" result.loadFileRepresentationForTypeIdentifier(identifier, WeakAddressOf LoadFileRepresentationCompleted) end if End Sub
Property Picker As PHPickerViewController
Property Results() As PHPickerResultMBS
Property Private 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"
MenuItem HelpMenu = "&Help"
End MenuBar
Class PHPickerViewController Inherits PHPickerViewControllerMBS
ComputedProperty ParentWindow As MainWindow
Sub Set() if value = nil then mParentWindow = Nil else mParentWindow = new WeakRef(value) end if End Set
Sub Get() If mParentWindow <> Nil Then Dim v As Variant = mParentWindow.Value return v end if End Get
End ComputedProperty
EventHandler Sub didFinishPicking(Result() as PHPickerResultMBS) ParentWindow.PickerFinished result self.Dismiss End EventHandler
Property Private mParentWindow As weakRef
End Class
End Project

See also:

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


The biggest plugin in space...