cordova plugin add org.apache.cordova.camera2、在index.html中,添加以下列表项到员工模板:
<li class="table-view-cell media"> <a hre="#" class="push-right change-pic-btn"> <span class="media-object pull-left"></span> <div class="media-body"> Change Picture </div> </a> </li>3、在EmployeeView的initialize()函数中,为Change Picture列表项的单击事件注册一个事件侦听器。
this.$el.on('click', '.change-pic-btn', this.changePicture);
4、在EmployeeView中,定义changePicture事件处理程序如下:this.changePicture = function(event) {
event.preventDefault();
if (!navigator.camera) {
alert("Camera API not supported", "Error");
return;
}
var options = { quality: 50,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: 1, // 0:Photo Library, 1=Camera, 2=Saved Album
encodingType: 0 // 0=JPG 1=PNG
};
navigator.camera.getPicture(
function(imgData) {
$('.media-object', this.$el).attr('src', "data:image/jpeg;base64,"+imgData);
},
function() {
alert('Error taking picture', 'Error');
},
options);
return false;
};
5、测试应用 邮箱 626512443@qq.com
电话 18611320371(微信)
QQ群 235681453
Copyright © 2015-2024
备案号:京ICP备15003423号-3