当前位置:主页 > 移动开发 > Android代码 >

Android使用phonegap从相册里面获取照片(代码分享)

时间:2021-01-27 10:39:39 | 栏目:Android代码 | 点击:

话不多说,请看代码:

<!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>

您可能感兴趣的文章:

相关文章