Repository: JetBrains/compose-multiplatform
File: experimental/examples/imageviewer/shared/src/androidMain/kotlin/example/imageviewer/view/CameraView.android.kt (Kotlin)

Code before:
                    }
                    LocationServices.getFusedLocationProviderClient(context)
                        .getCurrentLocation(CurrentLocationRequest.Builder().build(), null)
                        .apply {
                            addOnSuccessListener {
                                sendToStorage(GpsPosition(it.latitude, it.longitude))
                            }
                            addOnFailureListener {
                                sendToStorage(GpsPosition(0.0, 0.0))
                            }
                        }
                }

                capturePhotoStarted = true
                imageCapture.takePicture(executor, object : OnImageCapturedCallback() {
                    override fun onCaptureSuccess(image: ImageProxy) {
                        val byteArray: ByteArray = image.planes[0].buffer.toByteArray()
                        val imageBitmap = byteArray.toImageBitmap()
                        image.close()
                        addLocationInfoAndReturnResult(imageBitmap)
                    }
                })
                viewScope.launch {
                    // TODO: There is known issue with Android emulator
                    //  https://partnerissuetracker.corp.google.com/issues/161034252
                    //  After 5 seconds delay, let's assume that bug appear and publish prepared photo
                    delay(5000)
                    if (capturePhotoStarted) {
                        addLocationInfoAndReturnResult(
                            resource("android-emulator-photo.jpg").readBytes().toImageBitmap()
                        )
                    }
                }
            }) {
            Text(LocalLocalization.current.takePhoto, color = Color.White)
        }
        if (capturePhotoStarted) {
            CircularProgressIndicator(
                modifier = Modifier.size(80.dp).align(Alignment.Center),
                color = Color.White.copy(alpha = 0.7f),
                strokeWidth = 8.dp,
            )
        }
    }
}

private fun ByteBuffer.toByteArray(): ByteArray {
    rewind()    // Rewind the buffer to zero
    val data = ByteArray(remaining())
    get(data)   // Copy the buffer into a byte array
    return data // Return the byte array

Review comment (bug):
TODO: There is **a** known issue with Android emulator
                    //  After 5 seconds delay, let's assume that **the** bug appear**s** and publish **a** prepared photo

Code after:
                    }
                    LocationServices.getFusedLocationProviderClient(context)
                        .getCurrentLocation(CurrentLocationRequest.Builder().build(), null)
                        .apply {
                            addOnSuccessListener {
                                sendToStorage(GpsPosition(it.latitude, it.longitude))
                            }
                            addOnFailureListener {
                                sendToStorage(GpsPosition(0.0, 0.0))
                            }
                        }
                }

                capturePhotoStarted = true
                imageCapture.takePicture(executor, object : OnImageCapturedCallback() {
                    override fun onCaptureSuccess(image: ImageProxy) {
                        val byteArray: ByteArray = image.planes[0].buffer.toByteArray()
                        val imageBitmap = byteArray.toImageBitmap()
                        image.close()
                        addLocationInfoAndReturnResult(imageBitmap)
                    }
                })
                viewScope.launch {
                    // TODO: There is a known issue with Android emulator
                    //  https://partnerissuetracker.corp.google.com/issues/161034252
                    //  After 5 seconds delay, let's assume that the bug appears and publish a prepared photo
                    delay(5000)
                    if (capturePhotoStarted) {
                        addLocationInfoAndReturnResult(
                            resource("android-emulator-photo.jpg").readBytes().toImageBitmap()
                        )
                    }
                }
            }) {
            Text(LocalLocalization.current.takePhoto, color = Color.White)
        }
        if (capturePhotoStarted) {
            CircularProgressIndicator(
                modifier = Modifier.size(80.dp).align(Alignment.Center),
                color = Color.White.copy(alpha = 0.7f),
                strokeWidth = 8.dp,
            )
        }
    }
}

private fun ByteBuffer.toByteArray(): ByteArray {
    rewind()    // Rewind the buffer to zero
    val data = ByteArray(remaining())
    get(data)   // Copy the buffer into a byte array
    return data // Return the byte array