Skip to main content
Supported on Android, iOS, macOS, JVM targets
FileKit Core provides powerful utilities for working with images across platforms. These utilities enable common image operations like compression, resizing, and saving to the device gallery, with a consistent API across all supported platforms.

Compressing Images

You can compress images to reduce their file size while maintaining acceptable quality:
The compressImage function provides several key features:
  • Quality control: Reduces the image quality based on the quality parameter (0-100)
  • Resizing: Resizes the image if maxWidth or maxHeight is specified, maintaining the aspect ratio
  • Format conversion: Converts the image to the specified format (JPEG or PNG)
  • Metadata handling: On Android, automatically handles EXIF orientation metadata
FileKit provides a way to save images to the device’s photo gallery:
The behavior of saveImageToGallery varies slightly by platform: FileKit provides a way to save videos to the device’s gallery:
The behavior of saveVideoToGallery varies slightly by platform:

Encoding and Converting Images

FileKit provides utilities for encoding ImageBitmap objects into byte arrays and converting PlatformFile objects into ImageBitmap instances. These methods are useful for image manipulation and storage across platforms.

Encoding an ImageBitmap to ByteArray

The ImageBitmap.encodeToByteArray method allows you to encode an ImageBitmap into a ByteArray using a specified format and quality.

Converting a PlatformFile to ImageBitmap

The PlatformFile.toImageBitmap method converts a file into an ImageBitmap for use in Compose UI or other image operations.

Example: Creating a Thumbnail

This function creates a thumbnail version of an image by resizing it to a maximum dimension while maintaining the aspect ratio.