
Modern camera toolkit delivering high-quality preview, capture, and image processing via modular plugins — includes QR scanning, OCR, and flexible image-saving for easy integration.
CameraK is a comprehensive camera library designed specifically for Compose Multiplatform applications. It currently supports Android, iOS, and JVM platforms, with plans for expansion.
Add the core library to your project:
implementation("io.github.kashif-mehmood-km:camerak:+")Image saving plugin:
implementation("io.github.kashif-mehmood-km:image_saver_plugin:0.0.7")QR scanning plugin:
implementation("io.github.kashif-mehmood-km:qr_scanner_plugin:0.0.8")OCR plugin:
implementation("io.github.kashif-mehmood-km:ocr_plugin:0.0.3")Add these permissions to your AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />Add these keys to your Info.plist:
<key>NSCameraUsageDescription</key>
<string>Camera permission is required for the app to work.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Photo Library permission is required for the app to work.</string>// Initialize and check permissions
val cameraPermissionState = remember { mutableStateOf(permissions.hasCameraPermission()) }
val storagePermissionState = remember { mutableStateOf(permissions.hasStoragePermission()) }
// Request permissions if needed
if (!cameraPermissionState.value) {
permissions.RequestCameraPermission(
onGranted = { cameraPermissionState.value = true },
onDenied = { println("Camera Permission Denied") }
)
}
if (!storagePermissionState.value) {
permissions.RequestStoragePermission(
onGranted = { storagePermissionState.value = true },
onDenied = { println("Storage Permission Denied") }
)
}val cameraController = remember { mutableStateOf<CameraController?>(null) }
// Configure plugins if needed
val imageSaverPlugin = rememberImageSaverPlugin(
config = ImageSaverConfig(
isAutoSave = false,
prefix = "MyApp",
directory = Directory.PICTURES,
customFolderName = "MyAppPhotos" // Android only
)
)
val qrScannerPlugin = rememberQRScannerPlugin(coroutineScope = coroutineScope)
// Set up QR code detection
LaunchedEffect(Unit) {
qrScannerPlugin.getQrCodeFlow().distinctUntilChanged()
.collectLatest { qrCode ->
println("QR Code Detected: $qrCode")
qrScannerPlugin.pauseScanning()
}
}CameraPreview(
modifier = Modifier.fillMaxSize(),
cameraConfiguration = {
setCameraLens(CameraLens.BACK)
setFlashMode(FlashMode.OFF)
setImageFormat(ImageFormat.JPEG)
setDirectory(Directory.PICTURES)
addPlugin(imageSaverPlugin)
addPlugin(qrScannerPlugin)
},
onCameraControllerReady = {
cameraController.value = it
qrScannerPlugin.startScanning()
}
)
// Display your custom camera UI once controller is ready
cameraController.value?.let { controller ->
CameraScreen(cameraController = controller, imageSaverPlugin)
}Button(
onClick = {
scope.launch {
when (val result = cameraController.takePicture()) {
is ImageCaptureResult.Success -> {
// Handle the captured image
val bitmap = result.byteArray.decodeToImageBitmap()
// Manually save the image if auto-save is disabled
if (!imageSaverPlugin.config.isAutoSave) {
imageSaverPlugin.saveImage(
byteArray = result.byteArray,
imageName = "Photo_${System.currentTimeMillis()}"
)
}
}
is ImageCaptureResult.Error -> {
println("Image Capture Error: ${result.exception.message}")
}
}
}
}
) {
Text("Capture")
}Check the sample app in the repository for a complete implementation showcasing all features, including:
CameraK features a powerful plugin API that allows developers to extend its functionality. Explore the qrScannerPlugin or imageSaverPlugin source code for examples of how to build your own plugins.
This library is currently in experimental stage. APIs may change in future releases.
For comprehensive information about CameraK:
Contributions are welcome! Before submitting a pull request:
If you find this library useful, consider supporting the developer:
MIT License
CameraK is a comprehensive camera library designed specifically for Compose Multiplatform applications. It currently supports Android, iOS, and JVM platforms, with plans for expansion.
Add the core library to your project:
implementation("io.github.kashif-mehmood-km:camerak:+")Image saving plugin:
implementation("io.github.kashif-mehmood-km:image_saver_plugin:0.0.7")QR scanning plugin:
implementation("io.github.kashif-mehmood-km:qr_scanner_plugin:0.0.8")OCR plugin:
implementation("io.github.kashif-mehmood-km:ocr_plugin:0.0.3")Add these permissions to your AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />Add these keys to your Info.plist:
<key>NSCameraUsageDescription</key>
<string>Camera permission is required for the app to work.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Photo Library permission is required for the app to work.</string>// Initialize and check permissions
val cameraPermissionState = remember { mutableStateOf(permissions.hasCameraPermission()) }
val storagePermissionState = remember { mutableStateOf(permissions.hasStoragePermission()) }
// Request permissions if needed
if (!cameraPermissionState.value) {
permissions.RequestCameraPermission(
onGranted = { cameraPermissionState.value = true },
onDenied = { println("Camera Permission Denied") }
)
}
if (!storagePermissionState.value) {
permissions.RequestStoragePermission(
onGranted = { storagePermissionState.value = true },
onDenied = { println("Storage Permission Denied") }
)
}val cameraController = remember { mutableStateOf<CameraController?>(null) }
// Configure plugins if needed
val imageSaverPlugin = rememberImageSaverPlugin(
config = ImageSaverConfig(
isAutoSave = false,
prefix = "MyApp",
directory = Directory.PICTURES,
customFolderName = "MyAppPhotos" // Android only
)
)
val qrScannerPlugin = rememberQRScannerPlugin(coroutineScope = coroutineScope)
// Set up QR code detection
LaunchedEffect(Unit) {
qrScannerPlugin.getQrCodeFlow().distinctUntilChanged()
.collectLatest { qrCode ->
println("QR Code Detected: $qrCode")
qrScannerPlugin.pauseScanning()
}
}CameraPreview(
modifier = Modifier.fillMaxSize(),
cameraConfiguration = {
setCameraLens(CameraLens.BACK)
setFlashMode(FlashMode.OFF)
setImageFormat(ImageFormat.JPEG)
setDirectory(Directory.PICTURES)
addPlugin(imageSaverPlugin)
addPlugin(qrScannerPlugin)
},
onCameraControllerReady = {
cameraController.value = it
qrScannerPlugin.startScanning()
}
)
// Display your custom camera UI once controller is ready
cameraController.value?.let { controller ->
CameraScreen(cameraController = controller, imageSaverPlugin)
}Button(
onClick = {
scope.launch {
when (val result = cameraController.takePicture()) {
is ImageCaptureResult.Success -> {
// Handle the captured image
val bitmap = result.byteArray.decodeToImageBitmap()
// Manually save the image if auto-save is disabled
if (!imageSaverPlugin.config.isAutoSave) {
imageSaverPlugin.saveImage(
byteArray = result.byteArray,
imageName = "Photo_${System.currentTimeMillis()}"
)
}
}
is ImageCaptureResult.Error -> {
println("Image Capture Error: ${result.exception.message}")
}
}
}
}
) {
Text("Capture")
}Check the sample app in the repository for a complete implementation showcasing all features, including:
CameraK features a powerful plugin API that allows developers to extend its functionality. Explore the qrScannerPlugin or imageSaverPlugin source code for examples of how to build your own plugins.
This library is currently in experimental stage. APIs may change in future releases.
For comprehensive information about CameraK:
Contributions are welcome! Before submitting a pull request:
If you find this library useful, consider supporting the developer:
MIT License