我试图通过带有alpha Gradient的drawLine()绘制一颗彗星,但这些线条不会像这张图片那样完美连接:
http://s14.postimg.org/y5w6pgl6p/Screenshot_2013_07_09_16_14_21.png
路径可以是S形或C形或(保持移动)
使用此代码:
paint.setStrokeJoin(Paint.Join.BEVEL);
paint.setStrokeWidth(20);
paint.setShader(new LinearGradient(100,200,150,200, 0x00ffff00,0x44ffff00, Shader.TileMode.CLAMP));
canvas.drawLine(100, 200, 150, 200, paint);
paint.setShader(new LinearGradient(150,200,200,220, 0x44ffff00,0x88ffff00, Shader.TileMode.CLAMP));
canvas.drawLine(150, 200, 200, 220, paint);
paint.setShader(new LinearGradient(200, 220, 230, 230, 0x88ffff00, 0xccffff00, Shader.TileMode.CLAMP));
canvas.drawLine(200, 220, 230, 260, paint);
paint.setShader(new LinearGradient(230, 230, 230, 280, 0xccffff00, 0xffffff00, Shader.TileMode.CLAMP));
canvas.drawLine(230,260,230,310,paint);
setStrokeJoin()没有帮助drawLine / s
我将线条转换为路径,但渐变不会与整个路径一致
我也绘制形状而不是线条,以填充它们之间的空白区域,但是花费了很多时间和CPU来绘制动画线条。
还有其他想法吗?
答案 0 :(得分:1)
Path path = new Path();
path.moveTo(100, 200);
path.lineTo(150, 200);
path.lineTo(200, 220);
path.lineTo(230, 260);
path.lineTo(230,310);
Paint paint = new Paint();
paint.setShader(new LinearGradient(100,200,230,310, 0x00ffff00,0x44ffff00, TileMode.CLAMP));
paint.setStyle(Style.STROKE);
paint.setStrokeWidth(50);
canvas.drawPath(path, paint);
希望它有所帮助!