Android使用phonegap从相册里面获取照片(代码分享)
程序员文章站
2022-06-14 09:32:49
话不多说,请看代码:
话不多说,请看代码:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>take a photo</title> <script type="text/javascript" charset="utf-8" src="cordova.js"></script> <script type="text/javascript" charset="utf-8"> document.addeventlistener("deviceready", ondeviceready, false); function ondeviceready() { } //成功回调 function onphotosuccess(imageuri){ var myimage=document.getelementbyid('myimage'); myimage.style.display='block'; myimage.src=imageuri; } //失败回调 function onphotofail(message){ alert('failed beacause:'+message); } //获取照片 function getphoto(source){ navigator.camera.getpicture(onphotosuccess,onphotofail,{quality:50,sourcetype:source}); } </script> </head> <body> <button onclick="getphoto(camera.picturesourcetype.photolibrary);"> from photo library</button><br> <img style="display:none;" id="myimage" src=""/> </body> </html>
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!