ImagePickerKMP support extentions now and Web

Backer 16 28
calendar_todayschedule1 min read

ImagePickerKMP — New Extensions & Image Compression

Repository: ismoy/ImagePickerKMP


Overview

ImagePickerKMP now introduces powerful new extension functions and image compression features for more flexible image handling across Android, iOS and Web platforms.


Available Extension Functions

These new extensions allow you to easily convert captured or selected images into different formats — perfect for storage, UI display, graphics, or network use.

Function Returns Usage
loadBytes() ByteArray For file operations and storage
loadPainter() Painter For direct display in Compose UI
loadImageBitmap() ImageBitmap For Compose graphics operations
loadBase64() String For API calls and network transmission

Example Usage

// State variables
var showCamera by remember { mutableStateOf(false) }
var showGallery by remember { mutableStateOf(false) }
var capturedImage by remember { mutableStateOf<Painter?>(null) }
var selectedPhotos by remember { mutableStateOf<List<GalleryPhotoHandler.PhotoResult>>(emptyList()) }

// Camera with extension functions
if (showCamera) {
    ImagePickerLauncher(
        config = ImagePickerConfig(
            onPhotoCaptured = { result ->
                // Use extension functions to get different formats
                val imageBytes = result.loadBytes()        // For file operations
                val imagePainter = result.loadPainter()    // For UI display
                val imageBitmap = result.loadImageBitmap() // For graphics operations
                val imageBase64 = result.loadBase64()      // For API calls
                
                // Store the painter to display later
                capturedImage = imagePainter
                showCamera = false
            },
            onError = { showCamera = false },
            onDismiss = { showCamera = false },
            directCameraLaunch = true
        )
    )
}

// Gallery with extension functions
if (showGallery) {
    GalleryPickerLauncher(
        onPhotosSelected = { photos ->
            selectedPhotos = photos
            showGallery = false
        },
        onError = { showGallery = false },
        onDismiss = { showGallery = false },
        allowMultiple = true
    )
}

// Display captured image
capturedImage?.let { painter ->
    Image(
        painter = painter,
        contentDescription = "Captured photo",
        modifier = Modifier.size(200.dp)
    )
}

// Display selected photos
LazyColumn {
    items(selectedPhotos) { photo ->
        photo.loadPainter()?.let { painter ->
            Image(
                painter = painter,
                contentDescription = "Selected photo",
                modifier = Modifier
                    .fillMaxWidth()
                    .height(200.dp)
            )
        }
    }
}

gist: read More

1.4k Points44 Badges16 28
San Miguel, Chile
9Posts
7Comments
25Followers
I'm a passionate mobile & cross-platform developer who builds high-quality, production-ready tools and libraries.
I specialize in Kotlin Multiplatform, Jetpack Compose, and React N... Show more
Build your own developer journey
Track progress. Share learning. Stay consistent.

1 Comment

0 votes
🔥 Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

More Posts

React Native Quote Audit - USA

kajolshah - Mar 2

Merancang Backend Bisnis ISP: API Pelanggan, Paket Internet, Invoice, dan Tiket Support

Masbadar - Mar 13

Reelora Now Available on Indus Appstore – A New Era of Movie Discovery!

Dilip Kumar - Sep 29, 2025

ForgeZero: musl Cross-Compilation and Objective-C Support

alexvoste - Jun 6

Big News! Reelora is Now Available Worldwide!

Dilip Kumar - Jul 9, 2025
chevron_left

Related Jobs

View all jobs →

Commenters (This Week)

2 comments
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!