在android中获取特定的画布区域

时间:2017-08-18 06:46:08

标签: android canvas

我在android中使用画布,我画了一个圆圈,在屏幕中央有四个分区,半径为300

我被阻止如何只获得圆圈中的第一部分圆弧并填充或逐步操作,我不想在它上面重绘而不是用户在第一个圆弧中绘制我希望该区域并在其他区域重新绘制< / p>

我尝试获取computeBounds但是它也给了我第一个弧区域

我只需要在圆圈中的第一个圆弧的封闭边界区域,其中有4个圆弧意味着4个分区

任何帮助或提示都将不胜感激

1 个答案:

答案 0 :(得分:0)

public class CircleView extends View {

    Paint paint,paint1,paint2,paint3;

    public CircleView(Context context) {
        super(context);
    }

    public CircleView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        paint = new Paint();
        paint.setColor(Color.GREEN);
        paint1 = new Paint();
        paint1.setColor(Color.BLACK);
        paint2 = new Paint();
        paint2.setColor(Color.CYAN);
        paint3 = new Paint();
        paint3.setColor(Color.MAGENTA);


    }

    public CircleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public CircleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        RectF rectF = new RectF();
        rectF.set(50,20,900,480);
       // canvas.drawArc (rectF, 90, 45, true, paint);
       // canvas.drawArc (rectF, 180, 90, true, paint1);


        canvas.drawArc(rectF, 135, 180, false, paint);
        canvas.drawArc(rectF, 135, 180 - 1, false,paint1);
        canvas.drawArc(rectF, 90, 180+ 1, false,paint2);
        canvas.drawArc(rectF, 90, 180, false, paint3);
        canvas.drawArc(rectF, 45, 180, false, paint);


    }


}