Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

ClipPath does not work in .Droid project

I am implementing viewrenderer from xamarin.forms project in .Droid project.
I have drawn bitmap in specified rectangle and then I want to clip circle. So bitmap should only be visible in that circle and outside of the clipping area (remaining rectangle) should be transparent or removed.

but, somehow, my ClipPath does not seem to work. I tried to change regions while clipping path(like, Difference, Intersect,etc...) and PorterDuffXfermode also.

My code looks like this
public class Class1Renderer : ViewRenderer<Class1, Class1DemoView> { protected override void OnElementChanged(ElementChangedEventArgs<Class1> e) { base.OnElementChanged(e); if (Control == null) { Android.Views.View view1 = new Android.Views.View(Context); var view = new Class1DemoView(Context, Element, view1); SetNativeControl(view); } } } public class Class1DemoView : Android.Views.View { public Class1DemoView(Context context, Class1 skiaView, Android.Views.View view) : base(context) { } protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); Paint paint = new Paint(); paint.Color = Android.Graphics.Color.Pink; paint.StrokeWidth = 10; paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.DstOut)); paint.Alpha = 0; Rect dst = new Rect(0, 0, 200, 200); Paint newPaint = new Paint(); newPaint.Color = Android.Graphics.Color.Blue; Path newPath = new Path(); // canvas.DrawRect(dst, newPaint); canvas.DrawBitmap(bitmapToDisplay1, null, dst, newPaint); // canvas.ClipPath(newPath); newPath.AddCircle(100, 100, 50, Path.Direction.Ccw); canvas.DrawPath(newPath, newPaint); canvas.ClipPath(newPath,Region.Op.ReverseDifference); Rect rect1 = new Rect(300, 0, 500, 200); canvas.DrawBitmap(bitmapToDisplay1, null, rect1, newPaint); // canvas.DrawRect(rect1, newPaint); // canvas.Restore(); } }

My current output is square with defined bitmap an blue circle over it.
Can anybody help ?
Thank you.



Sign In or Register to comment.