[英]Draw a png on another png in a canvas
I'm making a rpg map creator in JS/Canvas for fun but I've a problem. 我正在用JS / Canvas做一个rpg地图创建者,但很有趣。 I can draw images on my canvas but I can't draw an image with transparency on another image already drawn on the canvas.
我可以在画布上绘制图像,但不能在画布上已经绘制的另一幅图像上绘制具有透明度的图像。
I would like the mushroom to be on the grass, not erase it. 我希望蘑菇在草地上,而不是抹掉。 The grid is just a helper, I have only 1 canvas and I draw my mushroom using
putImageData
. 网格只是一个助手,我只有1个画布,并且我使用
putImageData
绘制了蘑菇。
http://img11.hostingpics.net/thumbs/mini_31288520120419113247.png (we can see that the mushroom image has transparency) http://img11.hostingpics.net/thumbs/mini_31288520120419113247.png (我们可以看到蘑菇图像具有透明度)
http://img11.hostingpics.net/thumbs/mini_71357220120419113257.png (seems not working here) http://img11.hostingpics.net/thumbs/mini_71357220120419113257.png (似乎无法在此处使用)
I've you have any ideas, they are welcome. 我有任何想法,欢迎您。
Don't use putImageData as it will replace the pixels, use 不要使用putImageData,因为它将替换像素,请使用
context.drawImage(document.getElementById('mushroomImg'),0,0 );
//syntax : drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight)
JSFiddle with two images : http://jsfiddle.net/GVPfj/3/ JSFiddle具有两个图像: http : //jsfiddle.net/GVPfj/3/
( sadly, I couldn't find a mushroom with transparency, so it is a house :-) ) (可悲的是,我找不到透明的蘑菇,所以它是一栋房子:-))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.