【发布时间】:2012-03-23 22:58:46
【问题描述】:
我正在尝试使用以下方法将 base64 编码的字符串转换为图像对象。
function gotFileWriter(writer) {
console.log('Starting gotFileWriter');
writer.onwrite = function (evt) {
console.log("write success");
};
$.mobile.showPageLoadingMsg();
// console.log('height: ' + cb_canvas.height);
// console.log('width: ' + cb_canvas.width);
Signaturebase64 = cb_canvas.toDataURL();
//I need to save the base64 string to a PNG image on the Phone here.
writer.write(Signaturebase64 );
$.mobile.hidePageLoadingMsg();
$.mobile.changePage("#MyJob");
console.log('Finished gotFileWriter');
}
行:
Signaturebase64 = cb_canvas.toDataURL();
按预期工作并返回我的 base64 字符串。
我现在想做的是将其转换为手机永久存储上的图像文件。
以下行正在将 base64 字符串写入存储,但我想要它做的是将其保存为 PNG 文件:
writer.write(filedata);
【问题讨论】:
-
如果base64字符串只是编码后的图片数据,直接解码后写入带有图片扩展名的文件即可。
标签: javascript html cordova