Question

i am using SurfaceView to draw a circle like so :

        Canvas canvas = holder.lockCanvas();
        canvas.drawColor(android.R.color.holo_blue_bright);
        Paint paint = new Paint();
        paint.setStrokeWidth(0);
                paint.setARGB(255,255,138,253);
        canvas.drawCircle(canvas.getWidth() / 2, canvas.getHeight() / 2, (float) (lastAmp/ 1.2), paint);
            holder.unlockCanvasAndPost(canvas);

enter image description here

so the gray backdround is actually part of the linear layout that holds the SurfacrView. the pink circle is the part that i am drawing, the black part is what i like to get rid of, i want it to be transparent and to see the gray background below.

Was it helpful?

Solution

If you want to clear a part of the SurfaceView you can set this mode to the painter:

paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

then you can use it to draw whatever shape you want in order to obtain the effect. This basically means, "draw transparently".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top