我正在学习CameraX API,CameraXBasic是官方的示例代码。
CameraXBasic项目中的CameraFragment.kt可以显示实时摄像头预览。
现在我希望能够显示负片模式的预览,我应该如何使用CameraX API来实现?是否有示例代码?
CameraFragment.kt
private lateinit var viewFinder: TextureView
private fun bindCameraUseCases() {
// Get screen metrics used to setup camera for full screen resolution
val metrics = DisplayMetrics().also { viewFinder.display.getRealMetrics(it) }
val screenAspectRatio = Rational(metrics.widthPixels, metrics.heightPixels)
Log.d(TAG, "Screen metrics: ${metrics.widthPixels} x ${metrics.heightPixels}")
// Set up the view finder use case to display camera preview
val viewFinderConfig = PreviewConfig.Builder().apply {
setLensFacing(lensFacing)
// We request aspect ratio but no resolution to let CameraX optimize our use cases
setTargetAspectRatio(screenAspectRatio)
// Set initial target rotation, we will have to call this again if rotation changes
// during the lifecycle of this use case
setTargetRotation(viewFinder.display.rotation)
}.build()
// Use the auto-fit preview builder to automatically handle size and orientation changes
preview = AutoFitPreviewBuilder.build(viewFinderConfig, viewFinder)
....
CameraX.bindToLifecycle(
viewLifecycleOwner, preview, imageCapture, imageAnalyzer)
}
RenderScript
来实现这个功能。1. 如何在 cameraX 中使用 RenderScript https://gist.github.com/LiewJunTung/b9b7f8444037fbcbe5b30a915850d494 2. RenderScript 负效果 https://developer.android.com/reference/android/media/effect/EffectFactory.html#EFFECT_NEGATIVE - Froyo