简体   繁体   English

Android Phonegap插件中的Base64到PNG错误

[英]Base64 to PNG in Android Phonegap plugin ERROR

I'm fairly new to Phonegap and Java and trying to save an png to the sdcard. 我对Phonegap和Java相当陌生,并尝试将png保存到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 我一直在关注这篇文章以及那里采取的所有步骤: Phonegap插件:如何在Android中将Base64字符串转换为PNG图像

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? 当我调用saveImage方法时,只会收到以下警告:“无效操作”,我不确定为什么,对这个特定插件有更多经验的人吗?

The js code that calls the plugin method: 调用plugin方法的js代码:

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

revise your Base64ToPNG.js, the action should be "saveImage" 修改您的Base64ToPNG.js,操作应为“ 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 而且该插件在Base64ToPNG.java中有错误。

    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. 现在,插件应正确设置字符串格式。

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

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