简体   繁体   中英

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. Is it possible with phonegap (cordova) to create a image file (or phonegp plugin). Have not found anything for 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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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