Cheluis
Cheluis

Reputation: 1412

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

Upvotes: 1

Views: 113

Answers (1)

Variant
Variant

Reputation: 17385

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.

Upvotes: 1

Related Questions