Utilities for working with images in Kotlin Multiplatform
compressImage
function provides several key features:
quality
parameter (0-100)maxWidth
or maxHeight
is specified, maintaining the aspect ratiosaveImageToGallery
varies slightly by platform:
Platform | Behavior |
---|---|
Android | Saves to the device’s Pictures directory and makes it visible in the gallery app |
iOS | Saves to the device’s Camera Roll |
macOS/JVM | Saves to the user’s Pictures directory |
JS/WASM | Not supported (no-op) |
ImageBitmap
objects into byte arrays and converting PlatformFile
objects into ImageBitmap
instances. These methods are useful for image manipulation and storage across platforms.
ImageBitmap.encodeToByteArray
method allows you to encode an ImageBitmap
into a ByteArray
using a specified format and quality.
PlatformFile.toImageBitmap
method converts a file into an ImageBitmap
for use in Compose UI or other image operations.