开发者

Imagen from Canvas

开发者 https://www.devze.com 2023-03-23 16:45 出处:网络
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

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.
0

精彩评论

暂无评论...
验证码 换一张
取 消