Create cameraview (mask) on surfaceview in android

4.6k views Asked by At

I want to create a mask on camera surface view. see image below. mask is resizable. image will be clicked only by unblurred area. can anybody give idea how to create suh mask? thanks in advance.

Example

2

There are 2 answers

0
fadden On

You can't draw on the Surface of the SurfaceView that is receiving the camera preview.

You have two basic options: draw on the View part of the SurfaceView, treating it as a custom view, or create a second SurfaceView and layer it on top of the camera surface.

For the latter, you would use setZOrderMediaOverlay() to position the Surface above the camera Surface layer but below the View UI layer. You can use Canvas or GLES to draw on it. You can find an example of an activity with three SurfaceViews in Grafika's "multi-surface test".

0
George On

You can draw on a surfaceview with camera preview. You need to set the

setWillNotDraw(false);

in surfaceCreated override.

See: Extended SurfaceView's onDraw() method never called

So from there on, do all your drawing in onDraw as normal.