[英]Transparent image always on top of Canvas. Draw behind transparent image
Here is my jsfiddle : 这是我的jsfiddle :
Im looking for 2 things: 我正在寻找两件事:
i always want the transparent image: "https://s23.postimg.org/c3u19aeqz/bmap_Front.gif"
to be on top of the drawing/canvas. 我一直希望透明图像: "https://s23.postimg.org/c3u19aeqz/bmap_Front.gif"
位于图形/画布上方。 Lets call it layer foreground (lfg)
. 让我们将其称为layer front (lfg)
。 This image should never be overpainted. 该图像永远不能被粉刷过。
When i save my drawing as image. 当我将图形另存为图像时。 I only want to save the "drawings" that were drawn underneath the image. 我只想保存在图像下方绘制的“图形”。 This means saving everything except the transparent image. 这意味着保存除透明图像以外的所有内容。
I tried "playing" with: 我尝试了“玩”:
ctx.globalCompositeOperation = "source-over";
ctx.globalCompositeOperation = "destination-over";
and 和
<div id="LayerTown" class="containerChild" style="position: relative;">
<canvas id="canvas" style="position: absolute; left: 0; top: 0; z-index: 0;">
Update your browser
</canvas>
<img src='https://s23.postimg.org/c3u19aeqz/bmap_Front.gif' style="position: absolute; left: 0; top: 0; z-index: 1;">
</div>
So far nothing has helped me. 到目前为止,没有任何帮助。 Since im very new to html/css/js please consider alterating my fiddle if you want to help me, because i have a hard time understanding what i should do, if its just a command line. 由于我对html / css / js非常陌生,因此如果您想帮助我,请考虑更改我的小提琴,因为如果只是命令行,我很难理解应该怎么做。
Doing what you said in the OP, adding a image element on top of the canvas is the way to go. 按照您在OP中所说的那样,在画布顶部添加图像元素是一种方法。 By adding the CSS rule "pointer-events:none" you will be able to right click the canvas through the image and saving only what's on the canvas. 通过添加CSS规则“ pointer-events:none”,您将能够右键单击画布中的图像并仅保存画布中的内容。
<div id="LayerTown" class="containerChild" style="position: relative;">
<canvas id="canvas" style="position: absolute;">
Update your browser
</canvas>
<img src='https://s23.postimg.org/c3u19aeqz/bmap_Front.gif' style="position: absolute; pointer-events: none;">
</div>
You will also have to remove the addImg2Canvas() function from the script as we no longer want to draw the image on the canvas. 您还必须从脚本中删除addImg2Canvas()函数,因为我们不再希望在画布上绘制图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.