1

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

2 Answers 2

1

I solved it using phonegap-base64 plugin

Sign up to request clarification or add additional context in comments.

Comments

0

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/

2 Comments

I tested this solution before but the issue is that this code is very slow on android 2.3, do you have any other solution?
sorry this is all i know

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.