Search Docs
Loading...
Skip to content

Take Photo

Capture a still photo with the IMGLY Mobile Camera. Configure the camera for photo mode, launch it, and receive the captured photo so your app can edit, upload, or store it.

5 mins
estimated time
GitHub

This guide uses the IMGLY Mobile Camera in photo mode. For adding the camera to your app, see Integrate Mobile Camera; for the full set of camera options, see Mobile Camera Configuration.

The camera declares the required permissions in its library manifest and presents its own permission prompt the first time it opens; photo mode does not request the microphone. This sample uses evaluation mode with license = null; pass your production license and user ID through EngineConfiguration in your app.

Configure Photo Capture#

Set captureType = CaptureType.Photo on CameraConfiguration so the camera shoots still images instead of videos. Use CaptureCount.Single when the camera should return after one confirmed photo.

val singlePhotoInput = CaptureMedia.Input(
engineConfiguration = EngineConfiguration(
license = null, // pass null or empty for evaluation mode with watermark
userId = "<your unique user id>",
),
cameraConfiguration = CameraConfiguration(
captureType = CaptureType.Photo,
captureCount = CaptureCount.Single,
),
)

CaptureMedia.Input combines the engine configuration with the camera behavior for this launch. The photo is returned through the Activity Result callback as part of a CameraResult.Captures value.

Capture Multiple Photos#

Use CaptureCount.Multi when the user can take several photos before leaving the camera. Set showsPhotoPreview = false if every photo should be committed immediately without the confirm or discard preview.

val multiPhotoInput = CaptureMedia.Input(
engineConfiguration = EngineConfiguration(
license = null,
userId = "<your unique user id>",
),
cameraConfiguration = CameraConfiguration(
captureType = CaptureType.Photo,
captureCount = CaptureCount.Multi,
photoClipDuration = 4.seconds,
showsPhotoPreview = false,
),
)

photoClipDuration sets the duration stamped on each still photo: the photo occupies that much of the camera’s recording-segments ring and counts toward maxTotalDuration, and the editor uses it as the clip length if the photo is later placed on a timeline. It does not change the JPEG file itself.

Launch the Camera#

Register the CaptureMedia Activity Result contract and launch the input that matches the flow you want. The callback receives null whenever the camera closes without completing the session, including when the user discards photos they already captured.

val cameraLauncher = rememberLauncherForActivityResult(contract = CaptureMedia()) { result ->
handlePhotoResult(result)
}
Column {
Button(
onClick = {
cameraLauncher.launch(singlePhotoInput)
},
) {
Text(text = "Take Photo")
}
Button(
onClick = {
cameraLauncher.launch(multiPhotoInput)
},
) {
Text(text = "Take Multiple Photos")
}
}

Handle Captured Photos#

Photo sessions return CameraResult.Captures. Filter the capture stack for Capture.Photo entries, then read each photo’s uri and clipDuration.

private fun handlePhotoResult(result: CameraResult?) {
result ?: run {
Log.i(TAG, "Camera dismissed")
return
}
when (result) {
is CameraResult.Captures -> {
val photos = result.captures.filterIsInstance<Capture.Photo>()
for (photo in photos) {
// Copy the file behind photo.uri to app-owned storage here if the image must persist.
Log.i(TAG, "Captured photo: ${photo.uri}, clip duration: ${photo.clipDuration}")
}
}
else -> {
Log.i(TAG, "Unhandled result")
}
}
}

Each Capture.Photo.uri points to a JPEG written to your app’s files directory. Copy the file to a permanent location before relying on it outside the immediate camera or editor workflow. See Access Recordings for accessing and persisting captured media.

API Reference#

API Purpose
CaptureMedia() Creates the Activity Result contract that opens the Mobile Camera.
CaptureMedia.Input(engineConfiguration=_, cameraConfiguration=_, cameraMode=_) Supplies the engine and camera configuration for one camera launch.
EngineConfiguration(license=_, userId=_) Provides the license and optional user identifier used by the camera engine.
CameraConfiguration(captureType=_, captureCount=_, photoClipDuration=_, showsPhotoPreview=_) Chooses photo capture, single or multi capture behavior, per-photo clip duration, and photo preview behavior.
CameraResult.Captures.captures Returns the ordered capture stack from a standard camera session.
Capture.Photo.uri Returns the URI of the captured JPEG image.
Capture.Photo.clipDuration Returns the timeline duration assigned to the photo capture.

Next Steps#