是否可以创建透明画布

Sof*_*oft 6 canvas processing.js

我正在使用processing.js在javascript中开发一个画笔应用程序它正在使用一个canvas对象.我想在画布的背景上保留一个图像.在前台画一些东西.保存时我只需要获取前景数据.

为此,我们需要使画布对象透明,以便可见背景图像.

我没有看到任何使画布透明的选项.我怎么做?

Jar*_*red 13

更好的是,在你的pjs顶部放了:

/* @pjs transparent=true; */
Run Code Online (Sandbox Code Playgroud)

...然后在你的绘制循环中:

background(0, 0, 0, 0);
Run Code Online (Sandbox Code Playgroud)

瞧!

  • 使用*ProcessingJS*时的正确答案.它也解决了我的问题. (4认同)

Ira*_*lho 6

<canvas> 默认是透明的.

我已经做了一个概念证明,可以在这里找到:

http://irae.pro.br/lab/canvas_pie_countdown/

针对IE6,IE7,IE8,Firefox 2,Firefox 3,Chrome和iPhone进行了测试.

  • 这在使用其他画布库/ API时有效.请注意,原始海报说他需要使用*ProcessingJS*来完成,它将所有带有灰色背景的画布元素渲染为*default*.他想要覆盖此默认行为.Jared的答案实际上是正确的. (2认同)

War*_*rty 3

context.clearRect(0,0,width, height) 
Run Code Online (Sandbox Code Playgroud)

这就是您所需要的=)

请记住,您可以在画布对象上使用 CSS 样式。

canvas.style.position = "absolute";  
canvas.style.left = the x position of the div you're going over +"px";  
canvas.style.top = the y position of the div you're going over + "px";
Run Code Online (Sandbox Code Playgroud)