为了将画布图像保存到画廊,我尝试通过在 phonegap 中创建插件以及下面的一段 javascript 代码,但是在单击按钮后,我得到了“Uncaught TypeError: Cannot read property 'version' of undefined at file:///android_asset/www/index.html:18"
代码
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8" src="SavePhotoPlugin.js"></script>
<link rel="stylesheet" href="index.css" />
<script type="text/javascript">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
var element = document.getElementById('myCanvas');
}
function share() {
var canvas = document.getElementById("myCanvas");
window.savephotoplugin(canvas,"image/png",device.version,function(val){
//returns you the saved path in val
alert("Photo Saved: " + val);
});
}
</script>
</head>
<body>
<div >
<IMG SRC="loadin.png" ALT="some text" WIDTH=100 HEIGHT=100>
<button class="button" id="myCanvas" onclick="share()">SAVE </button>
</div>
我尝试使用cordova 2.2、2.9,所有版本保持不变,在2.3版本设备上测试。这是cordova版本设备的问题,还是其他问题,请任何人指出错误。