angularJS拍照

第一步:先上工程目录结构-------------------------------

114313_QipX_2252639.png

说明:开发测试的时候需要在真机上调试拍照功能 不懂的可以加JS前端群:JS前端(HTML5) 458633781

第二步:上主页面HTML-------------------------------index.html

<!DOCTYPE html>
<html>
<!--
    作者:152645239@qq.com
    时间:2015-03-07
    描述:已经在android下完成测试
    更多技术交流群:JS前端(HTML5) 458633781
    更多潮流请关注《心魅体》微信号:ilittlekiss
    -->

<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>心魅体</title>

<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">

<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->

<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>

<!-- cordova script (this will be a 404 during development) -->
<script src="lib/ngCordova/dist/ng-cordova.min.js"></script>
<script src="cordova.js"></script>

<!-- your app's js -->
<script src="js/app.js"></script>
<style>
body {
overflow: visible;
}
.row-center {
margin: 0 auto;
}
.addimg {
display: inline-block;
width: 100%;
height: auto;
min-height: 100px;
font-size: 3rem;
padding-left: 17px;
border: 1px dotted #4d4d4d;
}
.button {
color: #4d4d4d;
}
.colorred {
color: #F70000;
}
</style>
</head>

<body ng-app="starter" ng-controller="ExampleController">
<div class="bar bar-header bar-calm">
<div class="row">This is my take photos list page</div>
</div>
<div class="content has-header has-footer">
<div class="row">
<div class="col">
<img class="imgsize100 imgwidth" ng-show="imgurl !== undefined" ng-src="{{imgurl}}">
<button ng-click="takePicture(1)" ng-show="imgurl == undefined" class="addimg button button-icon ion-ios-plus-empty">&nbsp;</button>
</div>
<div class="col">
<img class="imgsize100 imgwidth" ng-show="imgur2 !== undefined" ng-src="{{imgur2}}">
<button ng-click="takePicture(2)" ng-show="imgur2 == undefined" class="addimg button button-icon ion-ios-plus-empty">&nbsp;</button>
</div>
<div class="col">
<img class="imgsize100 imgwidth" ng-show="imgur3 !== undefined" ng-src="{{imgur3}}">
<button ng-click="takePicture(3)" ng-show="imgur3 == undefined" class="addimg button button-icon ion-ios-plus-empty">&nbsp;</button>
</div>
</div>
<div class="row">
<div class="col">
<span class="colorred ion-ios-snowy"></span>&nbsp;点击“+”完成拍照,本次上传照片最多3张。
</div>
</div>
</div>

<div class="bar bar-footer bar-light">
<div class="button button-calm row-center">OK,SUBMIT</div>
</div>
</body>

</html>


第三步:上app.js-------------------------------takePhoto\www\js\app.js

// Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
var exampleApp = angular.module('starter', ['ionic','ngCordova'])
.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if(window.cordova && window.cordova.plugins.Keyboard) {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

      // Don't remove this line unless you know what you are doing. It stops the viewport
      // from snapping when text inputs are focused. Ionic handles this internally for
      // a much nicer keyboard experience.
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
});


exampleApp.controller("ExampleController", function($scope, $cordovaCamera) {
 
    $scope.takePicture = function() {
        var options = { 
            quality : 75, 
            destinationType : Camera.DestinationType.DATA_URL, 
            sourceType : Camera.PictureSourceType.CAMERA, 
            allowEdit : true,
            encodingType: Camera.EncodingType.JPEG,
            targetWidth: 300,
            targetHeight: 300,
            popoverOptions: CameraPopoverOptions,
            saveToPhotoAlbum: false
        };
 
        $cordovaCamera.getPicture(options).then(function(imageData) {
            $scope.imgURI = "data:image/jpeg;base64," + imageData;
        }, function(err) {
            // An error occured. Show a message to the user
        });
    }
 
});

源码链接:http://pan.baidu.com/s/1o6YviFw

转载于:https://my.oschina.net/u/2252639/blog/632057

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值