-
-
Save deepak140596/4229df904473b639c126cf36e6cd72a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun startCamera() { | |
// Create configuration object for the viewfinder use case | |
val previewConfig = PreviewConfig.Builder().apply { | |
setTargetAspectRatio(Rational(1, 1)) | |
setTargetResolution(Size(640, 640)) | |
}.build() | |
// Build the viewfinder use case | |
val preview = Preview(previewConfig) | |
// Every time the viewfinder is updated, recompute layout | |
preview.setOnPreviewOutputUpdateListener { | |
// To update the SurfaceTexture, we have to remove it and re-add it | |
val parent = viewFinder.parent as ViewGroup | |
parent.removeView(viewFinder) | |
parent.addView(viewFinder, 0) | |
viewFinder.surfaceTexture = it.surfaceTexture | |
updateTransform() | |
} | |
// Bind use cases to lifecycle | |
// If Android Studio complains about "this" being not a LifecycleOwner | |
// try rebuilding the project or updating the appcompat dependency to | |
// version 1.1.0 or higher. | |
CameraX.bindToLifecycle(this, preview) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment