Skip to main content
Language:

To Local Storage

Start Editor#

For the sake of this example, we load a photo from the resources into the photo editor.

Configure the PhotoEditorSaveSettings to save the exported photo to a custom Uri using the setOutputToUri() method. In this example, we create a file in the cache directory and get its Uri using the Uri.fromFile() method.

Handle Result#

The result from the editor is received in the onActivityResult() method. EditorSDKResult wraps around the intent and provides a convenient API to check the result. The Uri of the exported photo can be accessed via EditorSDKResult.resultUri.

File:
class SavePhotoToFile(private val activity: AppCompatActivity) : Example(activity) {
override fun invoke() {
// In this example, we do not need access to the Uri(s) after the editor is closed
// so we pass false in the constructor
val settingsList = PhotoEditorSettingsList(false)
// Set the source as the Uri of the image to be loaded
.configure<LoadSettings> {
it.source = activity.resourceUri(R.drawable.la)
}
// Save output to Uri
.configure<PhotoEditorSaveSettings> {
val file = File(activity.cacheDir, "imgly_photo.jpg")
it.setOutputToUri(Uri.fromFile(file))
}
// Start the photo editor using PhotoEditorBuilder
// The result will be obtained in onActivityResult() corresponding to EDITOR_REQUEST_CODE
PhotoEditorBuilder(activity)
.setSettingsList(settingsList)
.startActivityForResult(activity, EDITOR_REQUEST_CODE)
// Release the SettingsList once done
settingsList.release()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
super.onActivityResult(requestCode, resultCode, intent)
intent ?: return
if (requestCode == EDITOR_REQUEST_CODE) {
val result = EditorSDKResult(intent)
when (result.resultStatus) {
EditorSDKResult.Status.CANCELED -> showMessage("Editor cancelled")
EditorSDKResult.Status.EXPORT_DONE -> showMessage("Result saved at ${result.resultUri}")
else -> {
}
}
}
}
}