使用 Ionic Framework windows phone 8.1 相机
Use the windows phone 8.1 camera With Ionic Framework
I am creating an application with the ionic framework.
I need to use the device's camera.
I did test on Android and had no problem.
But on windows phone 8.1 could not use the camera. The code I'm using
is below.
cordova 插件添加 org.apache.cordova.camera
Adding dependency
angular.module('starter.menu', ['starter.services', 'ngCordova'])
<script src="js/lib/ng-cordova.min.js"></script>
$scope.takePicture = function () {
var options = {
quality: 100,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
encodingType: Camera.EncodingType.PNG,
targetWidth: 600,
targetHeight: 600,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false,
correctOrientation: true
};
$cordovaCamera.getPicture(options).then(function (imageData) {
var image = document.getElementById('myImage');
$scope.imgURI = "data:image/jpeg;base64," + imageData;
}, function (err) {
console.log("CAMERA ERROR - " + JSON.stringify(err));
});
}
我的观点
<ion-view cache-view="false" view-title="Title">
<ion-content style="margin : 5px !important;">
<img ng-show="imgURI !== undefined" ng-src="{{imgURI}}">
<img ng-show="imgURI === undefined" width="100%" ng-src="./img/placehold-800x500.jpg">
<button class="button" ng-click="takePicture()">Picture</button>
</ion-content>
</ion-view>
错误:JavaScript运行时错误:NotFoundError
navigator.camera.getPicture(cameraSuccess, cameraError, cameraOptions);
来源:https://github.com/apache/cordova-plugin-camera#module_camera.getPicture
I am creating an application with the ionic framework.
I need to use the device's camera.
I did test on Android and had no problem.
But on windows phone 8.1 could not use the camera. The code I'm using is below.
cordova 插件添加 org.apache.cordova.camera
Adding dependency
angular.module('starter.menu', ['starter.services', 'ngCordova'])
<script src="js/lib/ng-cordova.min.js"></script>
$scope.takePicture = function () {
var options = {
quality: 100,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
encodingType: Camera.EncodingType.PNG,
targetWidth: 600,
targetHeight: 600,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false,
correctOrientation: true
};
$cordovaCamera.getPicture(options).then(function (imageData) {
var image = document.getElementById('myImage');
$scope.imgURI = "data:image/jpeg;base64," + imageData;
}, function (err) {
console.log("CAMERA ERROR - " + JSON.stringify(err));
});
}
我的观点
<ion-view cache-view="false" view-title="Title">
<ion-content style="margin : 5px !important;">
<img ng-show="imgURI !== undefined" ng-src="{{imgURI}}">
<img ng-show="imgURI === undefined" width="100%" ng-src="./img/placehold-800x500.jpg">
<button class="button" ng-click="takePicture()">Picture</button>
</ion-content>
</ion-view>
错误:JavaScript运行时错误:NotFoundError
navigator.camera.getPicture(cameraSuccess, cameraError, cameraOptions);
来源:https://github.com/apache/cordova-plugin-camera#module_camera.getPicture