最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Save many canvas element as image - Stack Overflow

programmeradmin5浏览0评论

I have 3 layers of canvas - 1 is matrix, 2 & 3 is graphics, how to preserve them in one image?

<div style="position: relative;">
 <canvas id="matix" width="100" height="100" 
   style="position: absolute; left: 0; top: 0; z-index: 0;"></canvas>
 <canvas id="layer1" width="100" height="100" 
   style="position: absolute; left: 0; top: 0; z-index: 0;"></canvas>
 <canvas id="layer2" width="100" height="100" 
   style="position: absolute; left: 0; top: 0; z-index: 1;"></canvas>
</div>

I have 3 layers of canvas - 1 is matrix, 2 & 3 is graphics, how to preserve them in one image?

<div style="position: relative;">
 <canvas id="matix" width="100" height="100" 
   style="position: absolute; left: 0; top: 0; z-index: 0;"></canvas>
 <canvas id="layer1" width="100" height="100" 
   style="position: absolute; left: 0; top: 0; z-index: 0;"></canvas>
 <canvas id="layer2" width="100" height="100" 
   style="position: absolute; left: 0; top: 0; z-index: 1;"></canvas>
</div>
Share Improve this question edited Sep 23, 2010 at 4:36 ErgallM asked Sep 20, 2010 at 10:36 ErgallMErgallM 2373 silver badges9 bronze badges 3
  • Do you want them combined into 1 image on layered on top of each other or side by side? – Castrohenge Commented Sep 20, 2010 at 13:05
  • 1 combined into 1 image on layered on top of each other – ErgallM Commented Sep 20, 2010 at 14:04
  • How did you implemented layers? Are they separated canvas elements? First layer is matrix of what (do you mean pixel data?)? Is it something like this? stackoverflow.com/questions/3008635/… – pepkin88 Commented Sep 20, 2010 at 14:20
Add a comment  | 

1 Answer 1

Reset to default 23

You can draw one canvas into another with ctx.drawImage(other_canvas,0,0)

If you do that in the right order, you will have all the canvas contents correctly layered in one of them.

If you want to save the image, you can call canvas.toDataURL() to get the contents as a base64 encoded PNG file.

发布评论

评论列表(0)

  1. 暂无评论