首页 > 技术文章 > 调用手机相册和照相机

impossible1994727 2017-04-01 19:48 原文

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<style type="text/css">
.space{
width: 100px;
height: 100px;
background: aqua;
}
#image-list{
width: 110px;
height: 110px;
background: antiquewhite;
}
</style>
<body>
<div class="space" onclick="showActionSheet()">

</div>
</body>
<script type="text/javascript">
function showActionSheet(){
var bts = [{
title:"拍照"
},{
title:'从相册选择'
}];
plus.nativeUI.actionSheet(
{
cancel:'取消1',
buttons:bts
// buttons:[{title:'拍照'},{title:'从相册选择q'}]
},
function(e){
if(e.index == 1){
getImage();
}else if(e.index == 2){
galleryImgs();
}
})
}
//相机
function getImage(){
var cmr = plus.camera.getCamera();
cmr.captureImage(function(p){
plus.io.resolveLocalFileSystemURL(p,function(entry){
createItem(entry);
// compressImage(entry.toLocalURL(),entry.name);
},function(e){
plus.nativeUI.toast("错误"+e.message);
});
},function(e){
filter:'image'
})
}
//相册
function galleryImgs(){
plus.gallery.pick(function(e){
var name = e.substr(e.lastIndexOf('/')+1);
compressImage(e,name);
},function(e){
filter:'image'
})
}


</script>
</html>

推荐阅读