【发布时间】:2016-07-22 03:13:42
【问题描述】:
我正在构建一个带有相机插件的 Ionic 应用程序。 我需要解决的问题如下:
- 执行 Ionic 应用程序
- 通过
cordova-plugin-camera打开相机 -
拍照并用
FILE_URI检索数据,但是在第3步中,当我接收到带有URI的数据时,文件路径是这样的:file:///sdcard/emulated/0/..../142312321.jpg -
所以我将这个 uri 保存到
$scope.photo_uri并将<img/>标签设置为<img src="{{photo_uri}} />
但没有显示照片。我该如何解决这个问题?
代码如下:
$scope.onTakePhoto = function() {
if (typeof navigator.camera == 'undefined'){
alert("We'r sorry! Please try again on your Phone.^_^");
return;
}
var options = {
quality : 75,
destinationType : Camera.DestinationType.NATIVE_URI,
sourceType : Camera.PictureSourceType.CAMERA,
allowEdit : true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 300,
targetHeight: 300,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false
};
$cordovaCamera.getPicture(options).then(function (imageUri) {
//try{
var id = 'P_' + (new Date()).Format('MM_dd') + '_' + ($scope.photoList.length + 1);
//var data = "data:image/jpeg;base64," + imageData;
var date = (new Date()).Format('yyyy-MM-dd hh:mm P');
var name = 'PM_IMG_' + (new Date()).Format('yyyyMMddhhmmss') + '.jpg';
var location = gMyLocation.getData();
var uri = $scope.folder.uri;
window.resolveLocalFileSystemURL(imageUri, function(fileEntry) {
//If this doesn't work
$scope.camera_image_data.image = fileEntry.nativeURL;
console.log($scope.camera_image_data.image);
//Try this
//var image = document.getElementById('myImage');
//image.src = fileEntry.nativeURL;
});
//$scope.camera_image_data.image = 'cdv' + imageUri;
//alert('DataURI : '+ imageUri);
//createPhotoFile($scope.folder.uri, name, data, true);
//movePhotoFile(imageUri, uri, name);
var sPhoto = new PhotoObj(id,name,date,location,uri);
$scope.photoList.push(sPhoto);
//alert("PATH : " + $scope.photoList[0].uri +'\n'+
//'NAME : ' + $scope.photoList[0].name);
}, function (err) {
// error
console.log(err);
});
};
【问题讨论】:
标签: cordova camera ionic-framework cordova-plugins