Quickstart — Kotlin (Android)
Add the Android library module (AAR) to your app — see the repository
packages/kotlin for the Gradle setup. The bindings are generated by
UniFFI from the core, so the API matches the Rust core exactly.
Compress
Section titled “Compress”import uniffi.dusimagez.*
val input: ByteArray = File("input.jpg").readBytes()val output: ByteArray = compressImage(input, CompressOptions(quality = 80u))File("output.jpg").writeBytes(output)Compress to a target size
Section titled “Compress to a target size”// 200 KB or less, or a DusimagezException with code TARGET_SIZE_UNREACHABLE.val output = compressToSize(input, 200_000u, CompressOptions())Report and info
Section titled “Report and info”val info = getImageInfo(input)// info.format, info.width, info.height
val report = compressWithReport(input, CompressOptions(preset = Preset.WEB))println("${report.originalSize} -> ${report.outputSize} bytes, " + "saved ${report.savedPercent}%, quality ${report.qualityUsed}")val results = bulkCompress(listOf(data1, data2, ByteArray(0)), CompressOptions())for (result in results) { result.onSuccess { println("saved ${it.savedBytes} bytes") } result.onFailure { e -> println((e as DusimagezException).code) } // per-item error}Errors
Section titled “Errors”Failures throw DusimagezException with code, messageEn and
messageHi — see Error codes for all 9 codes.
Full option list: Options reference.