我正在尝试在Android上的PhoneGap应用中保存画布的内容。我正在使用Canvas2ImagePlugin,发现于: https://github.com/devgeeks/Canvas2ImagePlugin
对于我的生活,我无法让它发挥作用。我试图多次安装和重新安装但没有成功。
gotImageURI : function(fileEntry) {
var d = new Date();
var n = d.getTime();
//new file name
var newName = n + ".jpg";
fileEntry.moveTo(gFileSystem.root, newName, FileIO.movedImageSuccess, FileIO.errorHandler);
},
当尝试运行该功能时,我甚至没有得到警告说它有效或失败。它应该是一个非常简单的功能!
非常感谢任何帮助。
答案 0 :(得分:0)
我不知道这是否是最佳解决方案,但它适用于我,在HTML文件中添加包含<script src="js/app.js"></script>
的脚本 AFTER ,然后在其中添加一个事件监听器你刚刚创建的脚本
`
<script>
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
alert("Got deviceready");
var canvas2ImagePlugin = window.plugins.canvas2ImagePlugin;
}
// where myCanvasId == 'myCanvas' (the id of the canvas above)
function mySavingFunction(myCanvasId) {
canvas2ImagePlugin.saveImageDataToLibrary(
function(msg){
alert(msg);
alert("Saving image is successful!");
},
function(err){
alert(err);
},
myCanvasId
);
}
` 并在您的HTML文件中,执行此操作
<canvas id="myCanvas" width="165px" height="145px"></canvas>
<button onclick="mySavingFunction(myCanvas)">Save my canvas!</button>
如果您要在浏览器中测试它,首先构建项目然后将其安装在您的设备或设备模拟器中以使其工作,它将无法工作。
这是我得到answer的地方。希望这能解决你的问题。