特别是在画布上改变笔触不透明度而不是颜色 [英] Specifically change stroke opacity but not color on canvas

查看:75
本文介绍了特别是在画布上改变笔触不透明度而不是颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很好的整洁脚本循环显示颜色,它与 #xxxxxx 格式很好地配合,但我想改变透明度。有没有办法做到这一点?

I have a nice tidy script that cycles through colors and it works nicely with the #xxxxxx format, but I want to change the transparency. Is there a way to do that?

我指的是 ctx.strokeStyle()

这是当前代码:

canvas.strokeStyle = '#' + (((16777215 / s.length) * i).toString(16));

循环使用for $循环 i 每个周期增加 1 ,它是交换机的一部分。 for循环如下所示: for(var i = 0; i< s.length; i ++){}

It cycles through a for loop with i incremented by 1 each cycle and it's a part of a switch. The for loop looks like this: for(var i = 0; i < s.length; i++){}

推荐答案

在绘制所需的不透明度中的每个元素之前,您可以在0到1的范围内更改 ctx.globalAlpha

You can change ctx.globalAlpha in range of 0 to 1 before drawing each element in opacity you need.

这篇关于特别是在画布上改变笔触不透明度而不是颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆