【问题标题】:Possible to deep clone HTML5 canvas element with jQuery?可以使用 jQuery 深度克隆 HTML5 画布元素吗?
【发布时间】:2012-10-24 01:32:20
【问题描述】:

我们看到了这篇关于克隆 HTML5 画布元素的 SO 帖子:Any way to clone HTML5 canvas element with its content?

我们尝试使用 jQuery 进行深度克隆(即 $(canvas).clone(true) ),但图像数据似乎没有复制过来。

这不能用 jQuery 实现吗?

【问题讨论】:

  • $(canvas).clone(true, true))?
  • 不,不起作用。不过,谢谢。
  • 可能是一个愚蠢的问题,但您将克隆插入回 DOM,不是吗?
  • 可能的解决方案:forum.jquery.com/topic/…

标签: jquery html canvas html5-canvas


【解决方案1】:

如果您不需要复制任何附加的事件处理程序(一般来说,我怀疑这是可能的),我只会使用当前接受的解决方案 Display canvas image from one canvas to another canvas using base64

//grab the context from your destination canvas
var destCtx = destinationCanvas.getContext('2d');

//call its drawImage() function passing it the source canvas directly
destCtx.drawImage(sourceCanvas, 0, 0);

当然,您必须先创建目标画布,因此,在此之前,您必须:

var destinationCanvas    = document.createElement('canvas');
destinationCanvas.width  = sourceCanvas.width;
destinationCanvas.height = sourceCanvas.height;

【讨论】:

  • 这就是我们最终要做的事情。
猜你喜欢
  • 2011-03-20
  • 1970-01-01
  • 1970-01-01
  • 2011-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-31
  • 2014-06-07
相关资源
最近更新 更多