话不多说,请看代码:
<!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>
您可能感兴趣的文章:APP添加CNZZ统计插件教程 Android版添加phonegapPhonegap使用拍照功能时的内存问题phonegap教程使用jspdf库在应用中生成pdf文件(pdf生成方法)android判断phonegap是否联网且加载super.loadUrl网址深入理解移动前端开发之viewport自适应布局meta标签中viewport、content、width、initial-scale、minimum-scale、maximum-scale总结通过viewport实现jsp页面支持手机缩放关于viewport,Ext.panel和Ext.form.panel的关系ExtJs 学习笔记 Ext.Panle Ext.TabPanel Ext.Viewport解决PhoneGap不支持viewport的几种方法