2014-09-21 32 views
0

我有什么,是一个呈现静止图像的画布。一旦。然而,无论何时用户刷新,都必须再次渲染。有没有办法让用户渲染一次,然后将其存储在缓存中并稍后再使用它?或者这是不可能的?通过页面缓存画布

回答

1

已经知道了。使用canvas.toDataURL提供了base64编码的字符串,然后我可以稍后使用它来重新提供图像。示例代码:

if(typeof(Storage) !== "undefined") { 
    if(typeof localStorage.canvasCache != "undefined") { 
     // create the image tag 
    } else { 
     // render canvas 
     localStorage.canvasCache = canvas.toDataURL(); 
    } 
}