动态生成具有发光效果的线条

发布于 2024-11-14 06:17:20 字数 222 浏览 6 评论 0原文

我想画这样的带有发光效果的线
发光线
问题 - 我必须根据用户的交互在程序中生成此行(行的形式将在 onTouchEvent - ACTION_MOVE 中生成)。

我可以在没有 xml 文件或绘制 premaid 位图的情况下生成此效果吗?

I want to draw line with glow effect like this
glow line

The problem - i must generate this line in program in dependence on user's interaction ( the form of line will be generated in onTouchEvent - ACTION_MOVE ).

Can i generate this effect without xml files or drawing premaid bitmap ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ゝ偶尔ゞ 2024-11-21 06:17:20

我以这种方式模仿这种效果:

  1. BlurMaskFilter 画线
  2. 在其上画法线。

我使用 Path 类生成线条并保存 MOVE_ACTION 事件的坐标,以仅生成我需要的路径的一部分。

创建 2 个 Paint()

_paintSimple = new Paint();
_paintSimple.setAntiAlias(true);
_paintSimple.setDither(true);
_paintSimple.setColor(Color.argb(248, 255, 255, 255));
_paintSimple.setStrokeWidth(20f);
_paintSimple.setStyle(Paint.Style.STROKE);
_paintSimple.setStrokeJoin(Paint.Join.ROUND);
_paintSimple.setStrokeCap(Paint.Cap.ROUND);

_paintBlur = new Paint();
_paintBlur.set(_paintSimple);
_paintBlur.setColor(Color.argb(235, 74, 138, 255));
_paintBlur.setStrokeWidth(30f);
_paintBlur.setMaskFilter(new BlurMaskFilter(15, BlurMaskFilter.Blur.NORMAL)); 

并绘制两次我的 Path()

@Override
protected void onDraw(Canvas canvas) {
    canvas.drawPath(mPath, _paintBlur);
    canvas.drawPath(mPath, _paintSimple);
}

I imitate this effect in this way :

  1. Draw line with BlurMaskFilter;
  2. Draw over it normal line.

I use Path class to generate line and save coordinates of MOVE_ACTION event to generate only part of path what i need.

Create 2 Paint()s:

_paintSimple = new Paint();
_paintSimple.setAntiAlias(true);
_paintSimple.setDither(true);
_paintSimple.setColor(Color.argb(248, 255, 255, 255));
_paintSimple.setStrokeWidth(20f);
_paintSimple.setStyle(Paint.Style.STROKE);
_paintSimple.setStrokeJoin(Paint.Join.ROUND);
_paintSimple.setStrokeCap(Paint.Cap.ROUND);

_paintBlur = new Paint();
_paintBlur.set(_paintSimple);
_paintBlur.setColor(Color.argb(235, 74, 138, 255));
_paintBlur.setStrokeWidth(30f);
_paintBlur.setMaskFilter(new BlurMaskFilter(15, BlurMaskFilter.Blur.NORMAL)); 

And draw twice my Path():

@Override
protected void onDraw(Canvas canvas) {
    canvas.drawPath(mPath, _paintBlur);
    canvas.drawPath(mPath, _paintSimple);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文