Friday 25 September 2015

Using camera in ionic project

Hi,

Here is a cordova plugin for open a camera in ionic project-

Run the following command-

cordova plugin add org.apache.cordova.camera 

Then your main.html file look like-

<ion-view view-title="Profile">
    <ion-content>
            <div class="align-center">
     
                    <div class="user_img" ng-click="capture()">
                      Click here
                    </div>
</div> 
    </ion-content>
</ion-view>

And controller.js file look like-

myapp.controller('ProfileCtrl', function ($scope, $cordovaCamera) {
    var options = {
        quality: 50,
       destinationType: Camera.DestinationType.DATA_URL,
        sourceType: Camera.PictureSourceType.CAMERA,
        allowEdit: true,
        encodingType: Camera.EncodingType.JPEG,
        targetWidth: 150,
        targetHeight: 150,
        popoverOptions: CameraPopoverOptions,
        saveToPhotoAlbum: false,
        correctOrientation: true
    };
    $scope.capture = function () {
      $cordovaCamera.getPicture(options).then(function (imageData) {
            var image = document.getElementById('myImage');
            console.log("image",image)
            //image.src = "data:image/jpeg;base64," + imageData;
        }, function (err) {
            console.log("error",JSON.stringify(err))
        });
    }
});
 

Thanks


2 comments:

  1. Hi can you help me to upload camera image to php server in ionic app (base 64 image ) i can't able to upload base 64 image to php server

    Please replay

    Thank you

    ReplyDelete
  2. yes,tell me what is the problem for uploading the image over php server?

    ReplyDelete