Ng-cordova Mobile photos or select pictures from albums

Source: Internet
Author: User

1. Requirements Description

Implement a call camera to take pictures, or directly open the map library to select Photos, and then replace the image in the app function

2. Preparation

1) Install Ng-cordova

Go to the Ionic engineering catalog, install with the Bower tool,

    Bower Install Ngcordova

Then add Ng-cordova.js or Ng-cordova.min.js to the Cordova.js reference in index.html

...

<script src= "Lib/ngcordova/dist/ng-cordova.js" ></script>

<script src= "lib/cordova.js></script>

...

Adding Ngcordova dependencies in angular

Angular.module (' myApp ', [' Ngcordova '])

  2) Installation $cordovaCamera

   Cordova Plugin Add Cordova-plugin-camera

Adding dependencies to the controller

. Controller (' AppControl ', [' $cordovaCamera ']) {

...

}

3) Install $cordovaimagepicker

   Cordova Plugin Add Cordova-plugin-image-picker    

Adding dependencies to the controller

. Controller (' AppControl ', [' $cordovaImagePicker ']) {

...

}

3. Code implementation

  

1("Deviceready",function(){2//Take Pictures3varoptions={4Quality:50, //Save image quality, range 0-100 5DestinationType:Camera.DestinationType.DATA_URL, //return value format: Data_url=0, returned as Base64 encoded string; file_url=1, returns the URL of the image ; native_rul=2, return the image native URL 6SourceType:Camera.PictureSourceType.CAMERA, //Set Picture Source: photolibrary=0, Camera =1, 7AllowEdit:true, //whether to allow editing before selecting a picture 8EncodingType:Camera.EncodingType.JPEG, //jpen = 0,png = 1 9targetwidth:100, //Zoom the width of the image (in pixels) Tentargetheight:100, //scale image height (pixels)  Onepopoveroptions:camerapopoveroptions, //ios,ipad pop-up position  ASavetophotoalbum:true, //whether to save to album  -Correctorientation:true //Set whether the image taken by the camera is in the correct direction  -}; the$cordovaCamera. Getpicture (Options). Then (function(imageData) { -$scope. imagesrc= "Data:image/jpeg;base64," +ImageData; -},function(err) { -     //Error +}); -},false);
1Document.addeventlistener ("Deviceready",function(){2     varOptions = {3Maximumimagescount:10,//maximum number of pictures selected4width:800, //filter Width: If the width is 0, return all dimensions of the picture 5height:800, //filter Height: If the height is 0, return all dimensions of the picture 6Quality:80//image quality of the size, the default is7     };8$cordovaImagePicker. Getpictures (Options). Then (function(results) {9        for(vari = 0; i < results.length; i++) {TenAlert (' Image URI: ' +results[i]); One       } A},function(Error) { -       //Error getting photos -     }); the},false);

Ng-cordova Mobile photos or select pictures from albums

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.