1

In my app, I need to create a circle camera preview from Service. I create a CameraPreview class, which extends SurfaceView. In my service, I added CameraPreview object to WindowManager.

For getting circle, I override methods draw and dispatchDraw of SurfaceView:

    Path circ = new Path();
    circ.addCircle(canvas.getWidth() / 2, canvas.getWidth() / 2, canvas.getWidth() / 2, Path.Direction.CW);

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    canvas.drawPath(circ, paint);

    this.setZOrderOnTop(true);

Here are my results for 3 different tests:

  1. If I create CameraPreview object in Service, I get rectangle.

  2. If I create CameraPreview object in an Activity with no-transparent theme, I get circle.

  3. If I create CameraPreview object in an Activity with Theme.Translucent, I get rectangle.

Please tell me why I got these results. How does the theme of Activity affect to Canvas?

TOP
  • 2,574
  • 5
  • 35
  • 60

0 Answers0