Why is putImageData so slow?

后端 未结 4 778
梦谈多话
梦谈多话 2020-11-30 20:07

I am working with a relatively large Canvas where various (complex) stuff is drawn to. I then want to save the Canvas\' state, so I can quickly reset it to the state it now

4条回答
  •  生来不讨喜
    2020-11-30 20:46

    In Firefox 3.6.8 I was able to workaround the slowness of putImageData by using toDataUrl/drawImage instead. For me it's working fast enough that I can call it within handling a mousemove event:

    To save:

    savedImage = new Image()
    savedImage.src = canvas.toDataURL("image/png")
    

    The to restore:

    ctx = canvas.getContext('2d')
    ctx.drawImage(savedImage,0,0)
    

提交回复
热议问题