Imagen from Canvas
I'm trying to get the data from a canvas and set the src attribute of a img element. The problem here is that, the canvas has a background image setted with css, not with canvas methods. Is there any 开发者_开发知识库way or method to extract the background image so the toDataURL method could catch it?
Thanks
I guess there is a solid reason why you are not drawing the background image to the canvas itself so I can offer you this solution:
- Draw the background-image to a second canvas element positioned below the first canvas.
- When you want to take the canvas data and use it create a third canvas (no need to attach it to the DOM or make it visible.
- Draw the background canvas onto it and then draw the main canvas on top.
- Take the data from the third canvas.
- Voila.
精彩评论