First create an open class that extends the view. Inside the onDraw () method, draw your rectangle. For instance:
public class Box extends View { private Paint paint = new Paint(); Box(Context context) { super(context); } @Override protected void onDraw(Canvas canvas) {
Then, in camera preview mode, enter the instance in your Box class
Box box = new Box(this);
Then
addContentView(box, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
A green rectangle will be drawn on the cameraβs preview. Good luck Here is the link that helped me draw a camera preview
source share