如果我在画布上绘制矩形,请用纯色填充。是否可以用透明png重新填充它,这样我仍然可以在背景中看到原始颜色?Javascript - 画布 - 在previousley上填充透明png填充颜色
喜欢的东西,以虚设码 -
ctx.beginPath();
ctx.lineTo(//draw a rectangle)
ctx.fillStyle = "#FF0000"
ctx.fill();
var imageObj = new Image();
function drawPattern() {
var pattern = ctx.createPattern(imageObj, "repeat");
ctx.fillStyle = pattern;
ctx.fill();
}
imageObj.onload = drawPattern;
imageObj.src = "images/dot.png"; //transparent png
我已经尝试了类似的方法,它不工作。
是否有另一种方法呢?我错过了什么吗?
它为我在Chrome。你确定它是透明的吗? – pimvdb
嗯,将再次检查。谢谢 – Finnnn