Hazem Hagrass
Hazem Hagrass

Reputation: 9808

phonegap: Couldn't encode image to base64 on android 2.3

I have an issue in encoding images to base64 with phonegap, I tested the code over android 4 and iOS devices and it is working fine but when I tested it on android version 2.3 it didn't work. here is my code:

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);

        var dataUri = c.toDataURL("image/png");

       alert(dataUri);
    };
    img.src = filePath;

the output of this code on android 2.3 is always empty string

Upvotes: 1

Views: 409

Answers (2)

Hazem Hagrass
Hazem Hagrass

Reputation: 9808

I solved it using phonegap-base64 plugin

Upvotes: 1

Mohamed Salah
Mohamed Salah

Reputation: 1502

I think it isn't supported in your version, have a look at this issue reported

http://code.google.com/p/android/issues/detail?id=16829

There is supposed to be some sort of JavaScript implementation to add support for it, but i haven't tried it myself

http://code.google.com/p/todataurl-png-js/

Upvotes: 0

Related Questions