Platforms to show: All Mac Windows Linux Cross-Platform

/iOS/Photo Picker iOS


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

This example is the version from Tue, 31th Oct 2022.

Project "Photo Picker iOS.xojo_binary_project"
Class App Inherits MobileApplication
End Class
Class MainScreen Inherits MobileScreen
Control Button1 Inherits MobileButton
ControlInstance Button1 Inherits MobileButton
Constraint Constraint 1
Constraint Constraint 2
Constraint Constraint 3
Constraint Constraint 4
EventHandler Sub Pressed() 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.ParentScreen = self picker.Present End EventHandler
End Control
Control ImageViewer1 Inherits MobileImageViewer
ControlInstance ImageViewer1 Inherits MobileImageViewer
Constraint Constraint 1
Constraint Constraint 2
Constraint Constraint 3
Constraint Constraint 4
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 dim pic as Picture = Picture.Open(file) ImageViewer1.Image = pic #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 Dim pic As Picture = cgPic.Picture ImageViewer1.Image = pic #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
End Class
Class LaunchScreen Inherits iosView
End Class
Class PHPickerViewController Inherits PHPickerViewControllerMBS
ComputedProperty ParentScreen As MainScreen
Sub Set() if value = nil then mParentScreen = nil else mParentScreen = new WeakRef(value) end if End Set
Sub Get() if mParentScreen <> nil then dim v as Variant = mParentScreen.Value return v end if End Get
End ComputedProperty
EventHandler Sub didFinishPicking(Result() as PHPickerResultMBS) ParentScreen.PickerFinished result self.Dismiss End EventHandler
Property Private mParentScreen 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...