2011-04-25 4 views
0

dans mon code:comment dessiner la couleur progressive transparente

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; 
} 

vous connaissez ma peinture dessiner un changement gris, il est transparent et progressif, je DONOT savoir si je devrais utiliser paint.setColorFilter, pouvez-vous dites-moi comment faire

Répondre

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

êtes-vous une autre méthode, dans votre méthode ont dex, fromy, tox, jouet, parce que mon chemin est le changement dynamique. – pengwang

+0

Le code ci-dessus est juste un échantillon, fromx fromy tox toy indique la direction à laquelle le gradient doit s'appliquer. Vous pouvez obtenir des limites de chemin en appelant computeBounds de la classe Path –

Questions connexes