ionic 调用手机摄像头拍照, 选择本地视频, 选择本地图片 , 摸索半天没摸索到调用摄像头摄影的方法, 故只写了调本地视频文件方法 , 如有哪位大佬知道, 感谢分享
- $scope.imageList=new Array();
- // 调用摄像头拍照
- $scope.takePhoto=function(){
- var options = {
- quality: 100, // 相片质量 0-100
- destinationType: Camera.DestinationType.FILE_URI, // 返回类型: DATA_URL= 0, 返回作为 base64 編碼字串. FILE_URI=1, 返回影像档的 URI.NATIVE_URI=2, 返回图像本机 URI (例如, 資產庫)
- sourceType: Camera.PictureSourceType.CAMERA, // 从哪里选择图片: PHOTOLIBRARY=0, 相机拍照 = 1,SAVEDPHOTOALBUM=2.0 和 1 其实都是本地图库
- allowEdit: false, // 在选择之前允许修改截图
- encodingType:Camera.EncodingType.JPEG, // 保存的图片格式: JPEG = 0, PNG = 1
- mediaType:0, // 可选媒体类型: 圖片 = 0, 只允许选择图片將返回指定 DestinationType 的参数. 視頻格式 = 1, 允许选择视频, 最终返回 FILE_URI.ALLMEDIA= 2, 允许所有媒体类型的选择.
- cameraDirection:0, // 枪后摄像头类型: Back= 0,Front-facing = 1
- popoverOptions: CameraPopoverOptions,
- saveToPhotoAlbum: true // 保存进手机相册
- };
- $cordovaCamera.getPicture(options).then(function(imageData){
- $scope.imageList.push(imageData); // 存照片
- }, function(err) {
- // alert('相机启动失败!')
- });
- };
选择图库照片
- $scope.imageList=new Array();
- $scope.pickMore=function (){
- var options = {
- maximumImagesCount:9, // 需要显示的图片的数量
- width: 800,
- height: 800,
- quality: 80
- };
- $cordovaImagePicker.getPictures(options)
- .then(function (results) {
- for(var m =0;m<results.length;m++)
- {
- $scope.imageList.push(results[m]);
- }
- }, function (error) {
- alert('cordovaImagePicker 嘤嘤嘤 error');
- });
- }
选择本地视频文件
注: iOS 和安卓的路劲是有区别的
- $scope.imageList=new Array();
- $scope.addvideo = function() {
- var options = {
- quality: 50,
- destinationType: Camera.DestinationType.FILE_URI,
- sourceType: 0,
- mediaType: 1,// 为 1 时允许选择视频文件
- allowEdit: true,
- correctOrientation: true //Corrects Android orientation quirks
- };
- $cordovaCamera.getPicture(options).then(function(imageData){
- if(isIOS){
- $scope.imageList.push(imageData);
- }else{
- $scope.imageList.push("file://"+imageData);
- }
- }, function(err) {
- alert('相机启动失败!')
- });
- };
以上
来源: https://www.cnblogs.com/ycxwd/p/10696610.html