我从画布中得到base64编码的图像:
var dataURL = canvas.toDataURL( "image/png" );
然后我把它变成这样的数据:
//Remove the beginning identifier and use Chrome/Firefox?safari built int base64Decoder
var data = atob( dataURL.substring( "data:image/png;base64,".length ) );
然后我通过以下方式将其写入文件系统:
event.createWriter(
function(writerEvent)
{
//The success handler
writerEvent.onwriteend = function(finishEvent)
{
...
};
//Error handler
writerEvent.onerror = settings.error;
// Create a new Blob
var blob = new Blob( [ data ], { type: "image/png" } );
//Write it into the path
writerEvent.write( blob );
}
}
我尝试将其设置为这样的图像的 src:
document.getElementById( "saved" ).src = event.toURL();
这会写入文件,我可以找到它并获得一个 url(通过读取它并使用事件:event.toURL()
。但是图像在网页上显示为损坏的图像图标。我做错了什么?