当前Ionic 1 Camera插件实现 [英] Current Ionic 1 Camera plugin implementation

查看:185
本文介绍了当前Ionic 1 Camera插件实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为我的Ionic 1项目实施一个摄像头。



但是我找不到任何可靠的来源,如何做到这一点。
我发现:
https://www.thepolyglotdeveloper.com/2014/09/use-android-ios-camera-ionic-framework/

https://github.com/apache/cordova-plugin-camera
和一些较旧的stackoverflow条目。



但是没有让它运行到现在。
我的问题是:




  • 我需要安装什么插件(cordova / ion platform add ... cameraplugin

  • 什么Modul需要在app.js中绑定? (angle.module('starter',['ion',' cameraModule ']

  • 需要在控制器中绑定什么对象?控制器(CamCtrl,函数($ scope, $ cordovaCamera ))



帮助我知道在哪里或如何找到可靠的来源文档和引用Ionic,因为似乎有不同版本的每个。接下来我想尝试访问麦克风...; - )



感谢任何帮助。

解决方案

你已经在正确的轨道上!是Cordova最受欢迎的相机插件:



https://github.com/apache/cordova-plugin-camera



虽然这是一个纯科尔多瓦插件,这意味着它没有调整任何方式为离子,这意味着,你只需将它添加到您的项目,并可以使用它,一旦Ionic准备好了:

  ion.Platform.ready(function(){
navigator.camera.getPicture(onSuccess,onFail,options);
});

但是将回调传递为params确实不是有效的方法。因此,您可以添加ngCordova来增强处理能力。



要将ngCordova安装并添加到您的项目中,请按照以下步骤操作说明:



http://ngcordova.com/ docs / install /



将其包装起来:


  1. 通过bower安装ngCordova

  2. 将js引用添加到您的index.html

  3. 将ngCordova模块添加为您的app.js

  4. 如果您正确添加了所有内容,请在控制器,指令或服务中注入$ cordovaCamera以使用它。

这可以让您以有角度的方式访问相机,更多关于它可以在这里找到:



http://ngcordova.com/docs/plugins/camera/

  / ** 
*取自上面链接的文档
*你现在可以在这里使用承诺!
* /
$ cordovaCamera.getPicture(options).then(function(imageData){
var image = document.getElementById('myImage');
image.src = data:image / jpeg; base64,+ imageData;
},function(err){
// error
});

希望这有助于将相机成功集成到项目中。 ;)


Iam trying to implement a camera to my Ionic 1 project.

But I cant find any reliable sources how to do that. I found: https://www.thepolyglotdeveloper.com/2014/09/use-android-ios-camera-ionic-framework/ and https://github.com/apache/cordova-plugin-camera and some older stackoverflow entries.

But didnt make it running till now. My questions are:

  • What plugin do I need to install currently (cordova/ionic platform add ...cameraplugin)
  • What Modul do I need to bind in app.js then? (angular.module('starter', ['ionic', 'cameraModule']
  • What object to I need to bind in the controller then? (.controller("CamCtrl", function($scope, $cordovaCamera))

All about it would be a help for me to know where or how to find reliable sources docs and references to Ionic since there seems to be diffrent versions of each. Next I want to try to access the microphone... ;-)

Thanks for any help.

解决方案

You're on the right track already! What you found is the most popular camera plugin for Cordova:

https://github.com/apache/cordova-plugin-camera

This is a pure Cordova plugin though, meaning that it's not adjusted in any way for Ionic. This means, you just add it to your project and can use it as soon as Ionic is ready:

ionic.Platform.ready( function() {
  navigator.camera.getPicture(onSuccess, onFail, options);
});

But passing callbacks as params is indeed not the angular way to do this. So on top of the basic Cordova camera plugin you can add ngCordova to enhance the handling.

To install and add ngCordova to your project follow these instructions:

http://ngcordova.com/docs/install/

To wrap it up:

  1. Install ngCordova via bower
  2. Add js reference to your index.html
  3. Add the ngCordova module as a dependency to your app.js
  4. In case you've added everything correctly, inject $cordovaCamera in your controller, directive or service to use it.

This allows you to access the camera the angular way, more about it you can find here:

http://ngcordova.com/docs/plugins/camera/

/**
 * taken from the docs linked above
 * you can now make use of promises here!
 */
$cordovaCamera.getPicture(options).then(function(imageData) {
  var image = document.getElementById('myImage');
  image.src = "data:image/jpeg;base64," + imageData;
}, function(err) {
  // error
});

Hope this helps integrating the camera successfully in your project. ;)

这篇关于当前Ionic 1 Camera插件实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆