简体   繁体   English

Phonegap将base64字符串另存为图像

[英]Phonegap save base64 string as image

I have code, which looks like this: 我有代码,看起来像这样:

...
fileEntry.createWriter(function(fileWriter){
    fileWriter.write(imageData);
}, error);
...

where imageData is base64 string of image. 其中imageData是图像的base64字符串。 Is it possible with phonegap (cordova) to create a image file (or phonegp plugin). 是否可以使用phonegap(cordova)创建图像文件(或phonegp插件)。 Have not found anything for iOS. 尚未找到适用于iOS的任何内容。

Use this one 用这个

function encodeImageUri(imageData) {
    var c = document.createElement('canvas');
    var ctx = c.getContext("2d");
    var img = new Image();
    img.onload = function() {
        c.width = this.width;
        c.height = this.height;
        ctx.drawImage(img, 0, 0);
    };
    img.src = imageData;
    var dataURL = c.toDataURL("image/jpeg");
    return dataURL;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM