I'm creating a QR Scanner where the preview view is blur except the centre square part, I was able to blur PreviewView but not able to think of a way to unblur the centre cutout part.
AndroidView(
modifier = Modifier.fillMaxSize(),
factory = { context ->
val previewView = PreviewView(context).apply {
setRenderEffect( RenderEffect.createBlurEffect(
26f, 26f,Shader.TileMode.CLAMP))
implementationMode = PreviewView.ImplementationMode.COMPATIBLE
}
val preview = Preview.Builder().build()
val selector = CameraSelector.Builder().requireLensFacing(CameraSelector.LENS_FACING_BACK).build()
preview.setSurfaceProvider(previewView.surfaceProvider)
val imageAnalysis = ImageAnalysis.Builder().setTargetResolution(
Size(
previewView.width, previewView.height
)
).setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST).build()
imageAnalysis.setAnalyzer(
ContextCompat.getMainExecutor(context),
QrCodeAnalyzer { result ->
onScan(result)
})
try {
camera = cameraProviderFuture.get().bindToLifecycle(
lifecycleOwner, selector, preview, imageAnalysis, imageCapture
)
} catch (e: Exception) {
e.printStackTrace()
}
previewView
},
)
if (overlay != null) {
overlay()
}
Parent component:
ScannerArea: