2

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()
        }

Current Result

Rahul Pawar
  • 403
  • 3
  • 13
  • Hey, I am working on almost the same thing. I't trying to un text detection and I'm drawing an overlay over the Preview. How did you implement overlay()? – bogdan Jan 09 '23 at 17:48
  • For overlay I used composable canvas over AndroidView that draws PreviewView. – Rahul Pawar Jan 11 '23 at 11:32

0 Answers0