ImagePickerKMP support extentions now and Web

Backer posted 1 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 Comment

0 votes

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

I’m a Senior Dev and I’ve Forgotten How to Think Without a Prompt

Karol Modelskiverified - Mar 19

Big News! Reelora is Now Available Worldwide!

Dilip Kumar - Jul 9, 2025
chevron_left

Related Jobs

View all jobs →

Commenters (This Week)

1 comment
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!