Last active
February 18, 2018 19:52
-
-
Save ashwin-sp/d1b06be5df363c523ec06cbeae8c64d1 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
/** | |
* Begin a still image capture | |
*/ | |
fun takePicture() { | |
if (cameraDevice == | |
null) { | |
Log.w(TAG, "Cannot capture image. Camera not initialized.") | |
return | |
} | |
// Here, we create a CameraCaptureSession for capturing still images. | |
try { | |
cameraDevice.createCaptureSession( | |
listOf<Surface>(imageReader.getSurface()), | |
sessionCallback, null) | |
} catch (cae: CameraAccessException) { | |
Log.d(TAG, "access exception while preparing pic", cae) | |
} | |
} | |
/** | |
* Callback handling session state changes | |
*/ | |
private val sessionCallback = object : CameraCaptureSession.StateCallback() { | |
override fun onConfigured(cameraCaptureSession: CameraCaptureSession) { | |
// The camera is already closed | |
if (cameraDevice == null) { | |
return | |
} | |
// When the session is ready, we start capture. | |
captureSession = cameraCaptureSession | |
triggerImageCapture() | |
} | |
override fun onConfigureFailed(cameraCaptureSession: CameraCaptureSession) { | |
Log.w(TAG, "Failed to configure camera") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment