i
This is not the latest version of this document; to access the latest version, click here.
Official Content

The Photo Library API enables you to interact with the photo gallery of the device.

As the CameraAPI external object enables an app to interact with the photo camera of the device, this API allows the application to save or get an image from the native photo gallery.

This article focuses on what this API does and gives an example of how to use it in a Smart Device API.

Step 1: External Object

The API has one external object as the image shows.

PhotoLibraryEO

Methods:

ChooseImage This method invokes the native photo gallery app and lets the user choose one image to use in the application.
Save The Save method enables the application to store an image on the device's native photo gallery application.

 

There are three cases of different types of images for which the save method can be used.

a. To save an image from the DB (attribute)

b. To save an image from an URL(ImageVariable.FromURL(url))

c. To save an image just taken with the camera (CameraAPI)

Step 2: Code Sample

Create the following Panel object.

Layout:

photoLibraryLayout

Events:

Event Refresh
    &saveToLibFromWeb.FromURL('https://encrypted-tbn3.google.com/images?q=tbn:ANd9GcQ8n7HS90TxDvT4TcEphGN_AOxgwaOtUJ1rgM7f1puDi7851pcG1Q')
EndEvent
Event 'GetFromLibrary'
    &getFromLibrary = PhotoLibraryAPI.ChooseImage()
Endevent
Event 'saveFromURL'
    PhotoLibraryAPI.Save(&saveToLibFromWeb)
Endevent

Variables:

&saveToLibFromWeb -> Image data type
&getFromLibrary -> Image data type

Step 3: Execution

When the GetImage method is invoked:

photolibraryios1    photolibraryios2    photolibraryios3

The SaveImage method has no UI interaction to show, but the result of the execution is the image of the url saved on the device's photo gallery.

photolibraryios4

Availability

  • Implemented in iOS for GeneXus X  Evolution 2 Upgrade 1 and later.
  • Implemented in Android and Black Berry for GeneXus X Evolution 2 Upgrade 2 and later.



Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant