绘制:如何使用渐变图像或位图图像绘制圆弧

时间:2013-02-05 06:23:32

标签: android draw paint drawrect

我能够使用Paint绘制弧线并向其传递一些渐变颜色,我的问题是我需要使用渐变图像绘制弧线。是否可以使用图像绘制圆弧?

如果是这样怎么办?

这是我目前的代码:

Paint nPaint = new Paint();
        nPaint.setAntiAlias(true);
        nPaint.setDither(true);
        nPaint.setStrokeJoin(Paint.Join.ROUND);
        nPaint.setStrokeCap(Paint.Cap.ROUND);
        int gradientStart = getResources().getInteger(R.integer.gradient_start);
        int gradientend = getResources().getInteger(R.integer.gradient_end);

        nPaint.setShader(new RadialGradient(getWidth() / 2, getHeight() / 2, getWidth() / 2,
            gradientStart, gradientend, Shader.TileMode.CLAMP));

1 个答案:

答案 0 :(得分:0)

试试这段代码我希望这会对你有所帮助

     @Override
    protected void onDraw(Canvas canvas) {

        canvas.drawColor(Color.CYAN);
        Paint p = new Paint();
        // smooths
        p.setAntiAlias(true);
        p.setColor(Color.RED);
        p.setStyle(Paint.Style.STROKE); 
        p.setStrokeWidth(5);
        // opacity
        //p.setAlpha(0x80); //

        RectF rectF = new RectF(50, 20, 100, 80);
        canvas.drawOval(rectF, p);
        p.setColor(Color.BLACK);
        canvas.drawArc (rectF, 90, 45, true, p);
    }