admin管理员组文章数量:1415673
If I draw a rectangle on a canvas, fill it with a solid colour. Is it possible to fill it again with an transparent png, so that I can still see the original colour in the background?
Something like, dummy code -
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
I've tried a similar approach and it's not working.
Is there another way of doing this? Am I missing something?
If I draw a rectangle on a canvas, fill it with a solid colour. Is it possible to fill it again with an transparent png, so that I can still see the original colour in the background?
Something like, dummy code -
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
I've tried a similar approach and it's not working.
Is there another way of doing this? Am I missing something?
Share Improve this question edited Aug 10, 2011 at 9:24 Finnnn asked Aug 9, 2011 at 15:03 FinnnnFinnnn 3,6006 gold badges49 silver badges69 bronze badges 1- It works for me on Chrome. Are you sure it is transparent? – pimvdb Commented Aug 9, 2011 at 15:15
1 Answer
Reset to default 4What you've got will work just fine. Make sure you have a truly transparent PNG.
Here's a working example of your code:
http://jsfiddle/BDXc7/
本文标签: htmlJavascriptCanvasoverlaying a transparent png on a previousley filled colorStack Overflow
版权声明:本文标题:html - Javascript - Canvas - overlaying a transparent png on a previousley filled color - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745202147a2647436.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论