2017-10-09 2 views
2

다른 타원형 안에 타원형을 그려야하지만 두 번째 타원은 첫 번째 경계선에 도달하면 잘립니다.Android : 다른 모양 안에 도형을 그립니다.

이 원하는 결과입니다

는 어떻게 달성 할 수 있습니까?

+2

볼 \t'android.graphics.PorterDuffXfermode' , 그 이상 : http://ssp.impulsetrain.com/porterduff.html – pskink

답변

1

다른 타원형 내부에 타원형을 그려야하지만 첫 번째 경계선에 도달하면 두 번째 타원형을 잘라야합니다.

pskink 말했듯이,이 기능을 구현하기 위해 PorterDuffXfermode를 사용할 수는 여기에 간단하다

public class DrawView : View 
{ 
    public DrawView(Context context):base(context) 
    { 
    } 

    protected override void OnDraw(Canvas canvas) 
    { 
     base.OnDraw(canvas); 

     Paint paint = new Paint(); 
     paint.SetARGB(255, 255, 0, 0); 
     RectF oval2 = new RectF(60, 100, 300, 200); 
     canvas.DrawOval(oval2, paint); 

     //PorterDuff.Mode.SrcAtop means Discards the source pixels that do not cover destination pixels. Draws remaining source pixels over destination pixels 
     paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcAtop)); 

     paint.Color = Color.Black; 
     RectF oval3 = new RectF(110, 150, 350, 250); 
     canvas.DrawOval(oval3, paint); 

     this.SetLayerType(LayerType.Software, null); 
     paint.SetXfermode(null); 
    } 
} 

효과 :

enter image description here

+0

그것은 작동합니다! 고맙습니다! –

관련 문제