Skip to content

Instantly share code, notes, and snippets.

@pengj
Last active May 10, 2021 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pengj/25810b67f1cc6af0bc8220ac38e2f000 to your computer and use it in GitHub Desktop.
Save pengj/25810b67f1cc6af0bc8220ac38e2f000 to your computer and use it in GitHub Desktop.
private fun capture() {
// Create output file to hold the image
val photoFile = createFile(outputFolder, FILENAME, PHOTO_EXTENSION)
// Create output options object which contains file + metadata
val outputOptions = ImageCapture.OutputFileOptions.Builder(photoFile)
.build()
imageCapture.takePicture(outputOptions, Executors.newSingleThreadExecutor(),
object : ImageCapture.OnImageSavedCallback {
override fun onImageSaved(output: ImageCapture.OutputFileResults) {
captureFileUri = output.savedUri ?: Uri.fromFile(photoFile)
Log.d(TAG, "Photo capture succeeded: $captureFileUri")
}
override fun onError(exception: ImageCaptureException) {
Log.e(TAG, "Photo capture exception: $exception")
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment