画布 fillStyle 间隔透明/不透明
这个小代码间隔清除旧画布数据:
// start interval
ctx.save();
ctx.fillStyle = "rgba(0, 0, 0, 0.2)";
ctx.fillRect(0, 0, ctx.width, ctx.height);
ctx.restore();
//some draw code for new graph
...
//end interval
我的工作区域变黑,因为我将黑色设置为填充颜色(rgba(0, 0, 0, .2)
),但我需要透明背景,不是黑色。
我尝试使用 globalAlpha
和 imagePutData
但失败了。
我怎样才能做到这一点?
This small code clear old canvas data in interval:
// start interval
ctx.save();
ctx.fillStyle = "rgba(0, 0, 0, 0.2)";
ctx.fillRect(0, 0, ctx.width, ctx.height);
ctx.restore();
//some draw code for new graph
...
//end interval
My work area become black, because I set black as fill color (rgba(0, 0, 0, .2)
), but I need a transparent background, not black.
I tried use globalAlpha
and imagePutData
but I failed.
How I can do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为这会解决你的问题
I think this will resolve your issue
使用
rgba(0,0,0,.2)
fillStyle 和fillRect()
在 chrome 和 firefox 上都适用 - 它会绘制半透明的黑色填充。检查以确保您没有做其他导致某种完全不透明的油漆的事情。Using an
rgba(0,0,0,.2)
fillStyle andfillRect()
works for me on both chrome and firefox - it paints a semi-transparent black fill. Check to make sure you're not doing something else that's causing a fully opaque paint of some sort.尝试 ctx.canvas.width,而不是 ctx.width
try ctx.canvas.width, instead of ctx.width
您的问题解决了吗
我在使用 Windows 计算机时遇到了这个问题
我使用
opacity: .99
解决了这个问题Has your problem been solved
I encountered this problem while using Windows computer
I used
opacity: .99
solved this problem