Projemize buradaki ayarları yaptıktan sonra devam edelim. Camera Plugini telefondan resim çekmemizi sağlar. bu uygulamada telefonun kamerasıyla resim çekip uygulamaızda bu resmi göstereceğiz.
Plugin sayfası: http://ngcordova.com/docs/plugins/camera/
proje dizinimize gelip terminalden plugini ekleyelim:
$ cordova plugin add cordova-plugin-camera
Sayfa bağlantısını yapalım:
www/templates/camera.html
<ion-view view-title="Camera">
<ion-content>
<button class="button button-positive" ng-click="getPhoto()"> fotograf çek</button>
<br/>
<br/>
<img class="image-size" ng-src="{{image}}"/>
</ion-content>
</ion-view>
www/templates/menu.html
<ion-list>
*
*
<ion-item menu-close ui-sref="app.camera">
Camera
</ion-item>
*
*
</ion-list>
www/js/app.js içerisine aşağıdaki kodları yazalım
.state('app.camera',{
url:'/location',
views: {
'menuContent': {
templateUrl: 'templates/camera.html',
controller:'CameraCtrl'
}
}
})
www/js/controller.js içerisine:
.controller('CameraCtrl',function($scope, $cordovaCamera){
$scope.getPhoto=function(){
var options = {
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false,
correctOrientation:true
};
$cordovaCamera.getPicture(options).then(function(imageData) {
//var image = document.getElementById('myImage');
$scope.image="data:image/jpeg;base64," + imageData;
}, function(err) {
// error
});
}
})
Uygulamayı telefonda çalıştıralım:
Hiç yorum yok:
Yorum Gönder