How to Capture and Select Images in Jetpack Compose and KMP with ImagePickerKMP



This content originally appeared on HackerNoon and was authored by Ismoy Belizaire

If you’re building apps using Kotlin Multiplatform or Jetpack Compose — and you need to take photos or select images from the gallery — ImagePickerKMP is the library you’ve been waiting for.

It works seamlessly on Android and iOS, supports both Jetpack Compose Multiplatform and Android Native, and gives you full control over camera access, gallery selection, and UI customization.

What is ImagePickerKMP?

ImagePickerKMP is an open-source Kotlin Multiplatform library that lets you:

  • Launch the device camera with flash toggle, front/back switch, and image preview
  • Open the gallery with support for single or multiple selection
  • Handle permissions and photo access on Android and iOS without hassle
  • Customize confirmation dialogs and UI components (if needed)
  • Use the same API across Compose Multiplatform and Android Native

It’s built for developers who want simplicity, flexibility, and true multiplatform behavior.

Using ImagePickerKMP in Kotlin Multiplatform / Compose Multiplatform

Step 1: Add the dependency

In your commonMain build.gradle.kts:

implementation("io.github.ismoy:imagepickerkmp:1.0.1")

Don’t forget to configure iOS-specific permissions in your Info.plist file:

<key>NSCameraUsageDescription</key>
<string>We need access to the camera to capture a photo.</string>

Step 2: Launch the Camera

 var showCamera by remember { mutableStateOf(false) }
 var capturedPhoto by remember { mutableStateOf<CameraPhotoHandler.PhotoResult?>(null) }
if (showCamera) {
    ImagePickerLauncher(
        context = context, // Take a context in your App.kt
        config = ImagePickerConfig(
            onPhotoCaptured = { result ->
                capturedPhoto = result
                showCamera = false
            },
            onError = {
                showCamera = false
            }
        )
    )
}

Button(onClick = { showCamera = true }) {
    Text("Take Photo")
}

Step 3: Pick from the Gallery

var showGallery by remember { mutableStateOf(false) }
var selectedImages by remember { mutableStateOf<List<GalleryPhotoHandler.PhotoResult>>(emptyList()) }
if (showGallery) {
    GalleryPickerLauncher(
        context = context, // Take a context in your App.kt
        onPhotosSelected = { photos ->
            selectedImages = photos
            showGallery = false
        },
        onError = { error ->
            showGallery = false
        },
        allowMultiple = true, // False for single selection
        mimeTypes = listOf("image/jpeg", "image/png") // Optional: filter by type
    )
}

Button(onClick = { showGallery = true }) {
    Text("Choose from Gallery")
}

For more customization (confirmation views, MIME filtering, etc.), check out the integration guide for KMP.

Using ImagePickerKMP in Android Native (Jetpack Compose)

Even if you’re not using KMP, you can use ImagePickerKMP in pure Android projects with Jetpack Compose.

Step 1: Add the dependency

implementation("io.github.ismoy:imagepickerkmp:1.0.1")

Step 2: Camera Launcher Example

var showCamera by remember { mutableStateOf(false) }
var capturedPhoto by remember { mutableStateOf<CameraPhotoHandler.PhotoResult?>(null) }
val context = LocalContext.current
if (showCamera) {
    ImagePickerLauncher(
        context = context,
        config = ImagePickerConfig(
            onPhotoCaptured = { result ->
                capturedPhoto = result
                showCamera = false
            },
            onError = {
                showCamera = false
            }
        )
    )
}

Button(onClick = { showCamera = true }) {
    Text("Take Photo")
}

Step 3: Gallery Picker Example

var showGallery by remember { mutableStateOf(false) }
var selectedImages by remember { mutableStateOf<List<GalleryPhotoHandler.PhotoResult>>(emptyList()) }
val context = LocalContext.current
if (showGallery) {
    GalleryPickerLauncher(
        context = context,
        onPhotosSelected = { photos ->
            selectedImages = photos
            showGallery = false
        },
        onError = { error ->
            showGallery = false
        },
        allowMultiple = true, // False for single selection
        mimeTypes = listOf("image/jpeg", "image/png") // Optional: filter by type
    )
}

Button(onClick = { showGallery = true }) {
    Text("Choose from Gallery")
}

See the Android Native integration guide for more usage details.

Why Use It?

  • One single API for Android and iOS
  • Native UI and permission handling under the hood
  • Works great with Jetpack Compose and multiplatform projects
  • Open source, MIT licensed, and actively maintained Final Thoughts ImagePickerKMP is a versatile and easy-to-integrate solution that removes the pain of image selection across platforms. Whether you’re using Kotlin Multiplatform or just developing for Android, it has you covered — with a modern API and full Compose support. Use it, extend it, and make it yours.

GitHub Repository


This content originally appeared on HackerNoon and was authored by Ismoy Belizaire