从Base64字符串转换为PNG文件 [英] Convert from Base64 String to PNG File
问题描述
我正在尝试使用以下方法将base64编码的字符串转换为图像对象。
I am trying to convert a base64 encoded string to an image object using the method below.
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字符串。
Works as expected and gives me back my base64 string.
我现在想做的是将它转换为手机持久存储上的图像文件。
What I would like to do now is to convert it to an image file on the phone's persistent storage.
以下行是将base64字符串写入存储,但我想要它将其保存为PNG文件:
The following line is writing the base64 string to the storage but what I want it to do is save it as a PNG file instead:
writer.write(filedata);
推荐答案
你不能使用PhoneGap FileWriter写二进制文件数据。您需要编写一个插件来将base64编码数据发送到本机端,将其编码为二进制文件,然后使用本机代码编写它。
You can't use the PhoneGap FileWriter to write binary data. You'd need to write a plugin to send your base64 encoded data to the native side, encode it into binary then write it using native code.
这篇关于从Base64字符串转换为PNG文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!