0

I'm fairly new to Phonegap and Java and trying to save an png to the sdcard. I've been following this post and all steps taken there: Phonegap Plugin:How to convert Base64 String to a PNG image in Android

When I call the saveImage method I only get the alert with: "Invalid action" and I'm not sure why, anyone who has more experience with this particular plugin?

The js code that calls the plugin method:

function onDeviceReady(){
    var myCanvas = getCanvas();
    var myBase64 = myCanvas.toDataURL("image/png");
    //console.log(myBase64);
    //Shows how to use optional parameters
    window.plugins.base64ToPNG.saveImage(myBase64, {filename:"inbjudan.png", overwrite: true}, 
    function(result) {
        alert(result);
    }, function(error) {
        alert(error);
    });
}
Community
  • 1
  • 1
  • I do not know PhoneGap so can't really help you, but just thought i'd warn you that conversion to base64 isn't reliable for anything bigger then a couple of MB. A decent camera picture of 5~10 mb could already cause out-of-memory errors. – Stefan de Bruijn Mar 28 '13 at 15:24
  • I'm using canvas to assemble 3 png's the size of a postcard(420x298 px) or smaller with some text so I don't think the size of the outcome will be the problem – Omorose Mar 28 '13 at 15:58

1 Answers1

0

revise your Base64ToPNG.js, the action should be "saveImage"

    Base64ToPNG.prototype.savePDF = function(b64String, params, win, fail) {
        cordovaRef.exec(win, fail, "Base64ToPDF", "saveImage", [b64String, params]);
    };

And the plugin have errors in Base64ToPNG.java Change this

    String b64String = "";
    if (b64String.startsWith("data:image")) {
        b64String = args.getString(0).substring(21);
    } else {
        b64String = args.getString(0);
    }

for

    String b64String = "";
    if (args.getString(0).startsWith("data:image")) {
        b64String = args.getString(0).substring(22);
    } else {
        b64String = args.getString(0);
    }

Now the plugin should format the String correctly.