画布fillStyle在HTML5中没有 [英] Canvas fillStyle none in HTML5

查看:78
本文介绍了画布fillStyle在HTML5中没有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想在画布上填充任何颜色,即我希望背景div颜色应继续显示在div中.我已经用谷歌搜索过,但是没有找到任何方法来使fillStyle保持为无颜色.

I want to fill no color to canvas i.e. I want the background div color should keep on displaying in the div. I have googled it but didn't find any solution to keep fillStyle as no color.

我也尝试省略fillStyle,但是它使我变成了黑色.

Also I tried omitting the fillStyle but it leave me with black color.

有可用的选项吗?

谢谢

推荐答案

您需要使用它来清除画布:

You need to use this to clear the canvas:

context.clearRect(0, 0, canvas.width, canvas.height);

(或您需要的矩形).

还要确保没有为canvas元素的背景设置CSS规则(如果画布在初始化时 not 不透明,因为默认情况下画布是透明的,则可能是这种情况).

Also make sure you have no CSS rules set for the canvas element's background (which might be the case if your canvas is not transparent on init as canvas is transparent as default).

如果需要清除非规则形状,则可以使用复合模式:

If you need to clear a non-regular shape you can use composite mode:

context.globalCompositeOperation = 'destination-out';

( xor source-out 也可以在一定程度上用于删除现有像素,但有一些变化).

(xor and source-out can also be used too to a certain degree too to remove existing pixels but with some variations).

这将以您绘制的下一个形状(路径)的形式清除画布(或使用实心像素将清除画布的图像).

This will clear the canvas in the form of the next shape (Path) you draw (or use an image which solid pixels will clear the canvas).

这篇关于画布fillStyle在HTML5中没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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