2011-04-25 112 views
0

在我的代码:如何绘制透明渐变色

paint.setColor(Color.GRAY); 
paint.setAlpha(80); 
canvas.drawPath(getPath2(), paint); 

public static Path getPath2() 
{ 
    Path mPath2 = new Path(); 



    mPath2.moveTo(pta2.x, pta2.y); 
    mPath2.lineTo(pta.x, pta.y); 

    mPath2.lineTo(ptb.x, ptb.y); 

    mPath2.quadTo(ptl.x, ptl.y, ptd.x, ptd.y); 

    mPath2.close(); 
    return mPath2; 
} 
你知道我的油漆画一个灰色

,它不是透明的,并且逐步改变,我DONOT知道我是否应该使用paint.setColorFilter,你可以告诉我该怎么办

回答

3
Paint paint = new Paint(); 
paint.setStyle(Style.FILL); 
LinearGradient gradient = new LinearGradient(fromx, fromy, tox, toy, new int[]{color1, color2, color3}, new float[]{0, 0.6f, 1}, TileMode.CLAMP); 
paint.setShader(gradient); 
canvas.drawPath(getPath2(), paint); 
+0

是你的其他方法,在你的方法中有fromx,fromy,tox,toy,因为我的路径是动态变化的。 – pengwang 2011-04-25 11:02:11

+0

上面的代码只是一个示例,fromx fromy tox玩具指示应该应用渐变的方向。通过调用Path类的computeBounds可以获得路径边界 – 2011-04-25 11:18:01