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
val characteristics: CameraCharacteristics = ... | |
val context = this as Context // assuming we are inside of an activity | |
val surfaceViewSize = getPreviewOutputSize( | |
context, characteristics, SurfaceHolder::class.java) | |
val imageReaderSize = getPreviewOutputSize( | |
context, characteristics, ImageReader::class.java, format = ImageFormat.YUV_420_888) |
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
val characteristics: CameraCharacteristics = ... | |
// Hardware level will be one of: | |
// - CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY, | |
// - CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL, | |
// - CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED, | |
// - CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL, | |
// - CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_3 | |
val hardwareLevel = characteristics.get( | |
CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL) |
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
class SmartSize(width: Int, height: Int) { | |
var size = Size(width, height) | |
var long = max(size.width, size.height) | |
var short = min(size.width, size.height) | |
override fun toString() = "SmartSize(${long}x${short})" | |
} | |
val SIZE_1080P: SmartSize = SmartSize(1920, 1080) | |
fun getDisplaySmartSize(display: Display): SmartSize { |
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
fun <T>getMaximumOutputSize( | |
characteristics: CameraCharacteristics, targetClass: Class<T>, format: Int? = null): | |
Size { | |
val config = characteristics.get( | |
CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP) | |
// If image format is provided, use it to determine supported sizes; else use target class | |
val allSizes = if (format == null) | |
config.getOutputSizes(targetClass) else config.getOutputSizes(format) | |
return allSizes.sortedWith(compareBy { it.height * it.width }).reversed()[0] |
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
val characteristics: CameraCharacteristics = ... | |
val targetClass: Class<T> = ... // e.g. SurfaceView::class.java | |
val sizes = characteristics.get( | |
CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP) | |
.getOutputSizes(targetClass) |
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
val characteristics: CameraCharacteristics = ... | |
val outputFormat: Int = ... // e.g. ImageFormat.JPEG | |
val sizes = characteristics.get( | |
CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP) | |
.getOutputSizes(outputFormat) |
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
val characteristics: CameraCharacteristics = ... | |
val supportedFormats = characteristics.get( | |
CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP).outputFormats |
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
val session: CameraCaptureSession = ... // from CameraCaptureSession.StateCallback | |
// We will be using the preview capture template for the combined streams, because | |
// it is optimized for low latency; for high-quality images use | |
// TEMPLATE_STILL_CAPTURE and for a steady frame rate use | |
// TEMPLATE_RECORD | |
val requestTemplate = CameraDevice.TEMPLATE_PREVIEW | |
val combinedRequest = session.device.createCaptureRequest(requestTemplate) | |
// Link the Surface targets with the combined request |
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
val session: CameraCaptureSession = ... // from CameraCaptureSession.StateCallback | |
// Create the repeating request and dispatch it | |
val repeatingRequest = session.device.createCaptureRequest( | |
CameraDevice.TEMPLATE_PREVIEW) | |
repeatingRequest.addTarget(previewSurface) | |
session.setRepeatingRequest(repeatingRequest.build(), null, null) | |
// Some time later... |
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
val session: CameraCaptureSession = ... // from CameraCaptureSession.StateCallback | |
val captureRequest: CaptureRequest = ... // from CameraDevice.createCaptureRequest() | |
// This will keep sending the capture request as frequently as possible until the | |
// session is torn down or session.stopRepeating() is called | |
session.setRepeatingRequest(captureRequest.build(), null, null) |