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

If you read this far, tweet to the author to show them you care. Tweet a Thanks

1 Comment

0 votes

More Posts

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

Dilip Kumar - Sep 29

Big News! Reelora is Now Available Worldwide!

Dilip Kumar - Jul 9

Learn how Salesforce data migration services support a smooth and secure CRM system transition for businesses.

Dorian Sabitov - Apr 14

Release a heavy thought in 30 seconds with Clean My Mind, private and simple, try it now.

katormya0 - Sep 16

AI agents now autonomously protect, recover, and manage enterprise data without human intervention.

Tom Smith - Aug 19
chevron_left