DBCamera 轻量级定制摄像头

https://github.com/danielebogo/DBCamera

DBCamera is a simple custom camera with AVFoundation.

DBCamera使用了AVFoundation框架并简单的定制了摄像头.

Getting Started

Installation

The recommended approach for installating DBCamera is via the CocoaPods package manager, as it provides flexible dependency management and dead simple installation. For best results, it is recommended that you install via CocoaPods >= 0.16.0 using Git >= 1.8.0 installed via Homebrew.

推荐你使用CocoaPods安装.

Integration

DBCamera has a simple integration:

DBCamera模块化很简单:

#import "DBCameraViewController.h"
#import "DBCameraContainer.h"
//Add DBCameraViewControllerDelegate protocol
@interface RootViewController () <DBCameraViewControllerDelegate>
//Present DBCameraViewController with different behaviours

- (void) openCamera
{
DBCameraContainerViewController *cameraContainer = [[DBCameraContainerViewController alloc] initWithDelegate:self];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:cameraContainer];
[nav setNavigationBarHidden:YES];
[self presentViewController:nav animated:YES completion:nil];
} - (void) openCameraWithoutSegue
{
DBCameraContainerViewController *container = [[DBCameraContainerViewController alloc] initWithDelegate:self];
DBCameraViewController *cameraController = [DBCameraViewController initWithDelegate:self];
[cameraController setUseCameraSegue:NO];
[container setCameraViewController:cameraController];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:container];
[nav setNavigationBarHidden:YES];
[self presentViewController:nav animated:YES completion:nil];
} - (void) openCameraWithoutContainer
{
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[DBCameraViewController initWithDelegate:self]];
[nav setNavigationBarHidden:YES];
[self presentViewController:nav animated:YES completion:nil];
}
//Use your captured image
#pragma mark - DBCameraViewControllerDelegate - (void) captureImageDidFinish:(UIImage *)image withMetadata:(NSDictionary *)metadata
{
[_imageView setImage:image];
[self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
}

By default, DBCameraViewController has another controller to display the image preview. When you create DBCameraViewController instance, you can set useCameraSegue: NO, to avoid it.

默认情况下,DBCameraViewController有一个其他的controller来展示图片列表,当你创建这个DBCameraViewController实例时,你可以手动设置关闭它.

- (void) openCameraWithoutSegue
{
DBCameraContainerViewController *container = [[DBCameraContainerViewController alloc] initWithDelegate:self];
DBCameraViewController *cameraController = [DBCameraViewController initWithDelegate:self];
[cameraController setUseCameraSegue:NO];
[container setCameraViewController:cameraController];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:container];
[nav setNavigationBarHidden:YES];
[self presentViewController:nav animated:YES completion:nil];
}

Customizing the camera

Basic

For simple customizations, you can customize the built-in camera view by sending a cameraSettingsBlock to the view controller.

对于简单的定制,你可以给这个controller传递一个cameraSettingsBlock来实现内置照相机view的定制.

#import "DBCameraView.h"
- (void)openCameraWithSettings:(CDVInvokedUrlCommand*)command
{
DBCameraContainerViewController *cameraContainer = [[DBCameraContainerViewController alloc]
initWithDelegate:self
cameraSettingsBlock:^(DBCameraView *cameraView) {
[cameraView.gridButton setHidden:YES];
}]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:cameraContainer];
[nav setNavigationBarHidden:YES];
[self presentViewController:nav animated:YES completion:nil];
}

Advanced

You can also create a custom interface, using a subclass of DBCameraView

当然,你也可以自己创建一个界面,通过继承DBCameraView子类的方式来实现.

#import "DBCameraView.h"

@interface CustomCamera : DBCameraView
- (void) buildInterface;
@end
#import "CustomCamera.h"

@interface CustomCamera ()
@property (nonatomic, strong) UIButton *closeButton;
@property (nonatomic, strong) CALayer *focusBox, *exposeBox;
@end @implementation CustomCamera - (void) buildInterface
{
[self addSubview:self.closeButton]; [self.previewLayer addSublayer:self.focusBox];
[self.previewLayer addSublayer:self.exposeBox]; [self createGesture];
} - (UIButton *) closeButton
{
if ( !_closeButton ) {
_closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_closeButton setBackgroundColor:[UIColor redColor]];
[_closeButton setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
[_closeButton setFrame:(CGRect){ CGRectGetMidX(self.bounds) - 15, 17.5f, 30, 30 }];
[_closeButton addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
} return _closeButton;
} - (void) close
{
if ( [self.delegate respondsToSelector:@selector(closeCamera)] )
[self.delegate closeCamera];
} #pragma mark - Focus / Expose Box - (CALayer *) focusBox
{
if ( !_focusBox ) {
_focusBox = [[CALayer alloc] init];
[_focusBox setCornerRadius:45.0f];
[_focusBox setBounds:CGRectMake(0.0f, 0.0f, 90, 90)];
[_focusBox setBorderWidth:5.f];
[_focusBox setBorderColor:[[UIColor whiteColor] CGColor]];
[_focusBox setOpacity:0];
} return _focusBox;
} - (CALayer *) exposeBox
{
if ( !_exposeBox ) {
_exposeBox = [[CALayer alloc] init];
[_exposeBox setCornerRadius:55.0f];
[_exposeBox setBounds:CGRectMake(0.0f, 0.0f, 110, 110)];
[_exposeBox setBorderWidth:5.f];
[_exposeBox setBorderColor:[[UIColor redColor] CGColor]];
[_exposeBox setOpacity:0];
} return _exposeBox;
} - (void) drawFocusBoxAtPointOfInterest:(CGPoint)point andRemove:(BOOL)remove
{
[super draw:_focusBox atPointOfInterest:point andRemove:remove];
} - (void) drawExposeBoxAtPointOfInterest:(CGPoint)point andRemove:(BOOL)remove
{
[super draw:_exposeBox atPointOfInterest:point andRemove:remove];
} @end
//Present DBCameraViewController with a custom view.
@interface RootViewController () <DBCameraViewControllerDelegate> - (void) openCustomCamera
{
CustomCamera *camera = [CustomCamera initWithFrame:[[UIScreen mainScreen] bounds]];
[camera buildInterface]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[DBCameraViewController alloc] initWithDelegate:self cameraView:camera]];
[nav setNavigationBarHidden:YES];
[self presentViewController:nav animated:YES completion:nil];
}

[翻译] DBCamera 轻量级定制摄像头的更多相关文章

  1. js 打开摄像头方法 (定制摄像头)

    var video = document.getElementById("video");if (navigator.mediaDevices && navigat ...

  2. 安卓平台RTMP推流或轻量级RTSP服务(摄像头或同屏)编码前数据接入类型总结

    很多开发者在做Android平台RTMP推流或轻量级RTSP服务(摄像头或同屏)时,总感觉接口不够用,以大牛直播SDK为例 (Github) 我们来总结下,我们常规需要支持的编码前音视频数据有哪些类型 ...

  3. Android同屏、摄像头RTMP推送常用的数据接口设计探讨

    前言 好多开发者在调用Android平台RTMP推送或轻量级RTSP服务接口时,采集到的video数据类型多样化,如420sp.I420.yv12.nv21.rgb的,还有的拿到的图像是倒置的,如果开 ...

  4. 小白学Python——用 百度翻译API 实现 翻译功能

    本人英语不好,很多词组不认识,只能借助工具:百度翻译和谷歌翻译都不错,近期自学Python,就想能否自己设计一个百度翻译软件呢? 百度翻译开放平台: http://api.fanyi.baidu.co ...

  5. Android平台摄像头/屏幕/外部数据采集及RTMP推送接口设计描述

    好多开发者提到,为什么大牛直播SDK的Android平台RTMP推送接口怎么这么多?不像一些开源或者商业RTMP推送一样,就几个接口,简单明了. 不解释,以Android平台RTMP推送模块常用接口, ...

  6. 2018 AI产业界大盘点

    2018  AI产业界大盘点 大事件盘点 “ 1.24——Facebook人工智能部门负责人Yann LeCun宣布卸任 Facebook人工智能研究部门(FAIR)的负责人Yann LeCun宣布卸 ...

  7. 《iPhone高级编程—使用Mono Touch和.NET/C#》

    第1章 C#开发人员基于MonoTouch进行iPhone开发概述 1 1.1 产品对比 2 1.1.1 .NET Framework 2 1.1.2 Mono 2 1.1.3 MonoTouch 3 ...

  8. Bootstrap 简洁、直观、强悍、移动设备优先的前端开发框架,让web开发更迅速、简单。

    http://v3.bootcss.com/ 从2.x升级到3.0版本 Bootstrap 3并不向后兼容Bootstrap v2.x.下面章节列出的内容可以作为从v2.x升级到v3.0的通用指南.如 ...

  9. phonegap的照相机API

    1. Camera Api简单介绍 2. 拍照 3. 预览照片 一. Camera Api简单介绍 Camera选择使用摄像头拍照,或从设备相册中获取一张照片.图片以base64编码的 字符串或图片U ...

随机推荐

  1. tar 命令压缩时报错 tar: Removing leading `/' from member names

    在使用tar命令进行压缩打包的时候我们常常会遇到下面的错误.虽然它不会影响我们最后的压缩打包,但是间接说明了我们的命令是有问题的.接下来我们来看看解决的方法. 报错内容: [root@haha ~]# ...

  2. ABP-JavaScript API (转)

    转自:http://www.cnblogs.com/zd1994/p/7689164.html 因经常使用,备查 一.AJAX 1,ABP采用的方式 ASP.NET Boilerplate通过用abp ...

  3. Mybatis中同时使用shardbatis和pagehelper插件冲突问题

    在一次使用mybatis的插件,分表shardbatis+分页pagehelper共同使用的时候,会抛出以下异常: java.lang.NoSuchMethodError: net.sf.jsqlpa ...

  4. [转]ng-grid Auto / Dynamic Height

    本文转自:https://stackoverflow.com/questions/23396398/ng-grid-auto-dynamic-height I think I solved this ...

  5. eclipse相关问题处理

    maven,新建的web工程下,没有resource跟test目录,做法:https://blog.csdn.net/gengjianchun/article/details/78679036 项目右 ...

  6. Vertica添加磁盘

    本次实验环境是在虚拟机上 Vmware 12 操作系统是Centos 6.5 64位 1. 首先停止节点上的Vertica数据库,具体方法有很多 admintools -t stop_node -s ...

  7. 深入理解MyBatis的原理(一): 独立的入门demo

    前言:不结合spring,只有 mybatis+maven.数据库使用 oracle.不尝试永远不知道会发生什么事,其中遇到两个小问题,也记录下来了.转载请注明出处:https://www.cnblo ...

  8. K:图的存储结构

      常用的图的存储结构主要有两种,一种是采用数组链表(邻接表)的方式,一种是采用邻接矩阵的方式.当然,图也可以采用十字链表或者边集数组的方式来进行表示,但由于不常用,为此,本博文不对其进行介绍. 邻接 ...

  9. 【java基础】 == 和 equals() 的区别

    ==号和equals()方法都是比较是否相等的方法,那它们有什么区别和联系呢? 首先,==号在比较基本数据类型(指的值类型)时比较的是值,而用==号比较两个对象时比较的是两个对象的地址值: int x ...

  10. 【学习笔记】--- 老男孩学Python,day16-17 初识面向对象,类名称空间,查询顺序,组合

    面向过程 VS 面向对象 面向过程的程序设计的核心是过程(流水线式思维),过程即解决问题的步骤,面向过程的设计就好比精心设计好一条流水线,考虑周全什么时候处理什么东西. 优点是:极大的降低了写程序的复 ...