[翻译] DBCamera 轻量级定制摄像头
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 轻量级定制摄像头的更多相关文章
- js 打开摄像头方法 (定制摄像头)
var video = document.getElementById("video");if (navigator.mediaDevices && navigat ...
- 安卓平台RTMP推流或轻量级RTSP服务(摄像头或同屏)编码前数据接入类型总结
很多开发者在做Android平台RTMP推流或轻量级RTSP服务(摄像头或同屏)时,总感觉接口不够用,以大牛直播SDK为例 (Github) 我们来总结下,我们常规需要支持的编码前音视频数据有哪些类型 ...
- Android同屏、摄像头RTMP推送常用的数据接口设计探讨
前言 好多开发者在调用Android平台RTMP推送或轻量级RTSP服务接口时,采集到的video数据类型多样化,如420sp.I420.yv12.nv21.rgb的,还有的拿到的图像是倒置的,如果开 ...
- 小白学Python——用 百度翻译API 实现 翻译功能
本人英语不好,很多词组不认识,只能借助工具:百度翻译和谷歌翻译都不错,近期自学Python,就想能否自己设计一个百度翻译软件呢? 百度翻译开放平台: http://api.fanyi.baidu.co ...
- Android平台摄像头/屏幕/外部数据采集及RTMP推送接口设计描述
好多开发者提到,为什么大牛直播SDK的Android平台RTMP推送接口怎么这么多?不像一些开源或者商业RTMP推送一样,就几个接口,简单明了. 不解释,以Android平台RTMP推送模块常用接口, ...
- 2018 AI产业界大盘点
2018 AI产业界大盘点 大事件盘点 “ 1.24——Facebook人工智能部门负责人Yann LeCun宣布卸任 Facebook人工智能研究部门(FAIR)的负责人Yann LeCun宣布卸 ...
- 《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 ...
- Bootstrap 简洁、直观、强悍、移动设备优先的前端开发框架,让web开发更迅速、简单。
http://v3.bootcss.com/ 从2.x升级到3.0版本 Bootstrap 3并不向后兼容Bootstrap v2.x.下面章节列出的内容可以作为从v2.x升级到v3.0的通用指南.如 ...
- phonegap的照相机API
1. Camera Api简单介绍 2. 拍照 3. 预览照片 一. Camera Api简单介绍 Camera选择使用摄像头拍照,或从设备相册中获取一张照片.图片以base64编码的 字符串或图片U ...
随机推荐
- Catalina.createDigester方法详细理解
这个方法主要设置(这个方法很重要,贵在理解,虽然还没学过设计模式..) 1.遇到<server>标签时创建StandardServer实例 设置StandardServer类内部的相关 ...
- Word2vec 理解
1.有DNN做的word2vec,取隐藏层到softmax层的权重为词向量,softmax层的叶子节点数为词汇表大小 2-3的最开始的词向量是随机初始化的 2.哈夫曼树:左边走 sigmoid(当前节 ...
- linux更改文件权限
chown –Rh cheat:cheat /home/cheat/task/Cheat
- fail2ban的使用以及防暴力破解与邮件预警
fail2ban可以监视你的系统日志,然后匹配日志的错误信息(正则式匹配)执行相应的屏蔽动作(一般情况下是防火墙),而且可以发送e-mail通知系统管理员! fail2ban运行机制:简单来说其功能就 ...
- python线程入门
目录 python线程入门 线程与进程 线程 总结 参考 python线程入门 正常情况下,我们在启动一个程序的时候.这个程序会先启动一个进程,启动之后这个进程会启动起来一个线程.这个线程再去处理事务 ...
- RabbitMQ上手记录–part 3-发送消息
接上一part<<RabbitMQ上手记录–part 2 - 安装RabbitMQ>>,这里我们来看看如何通过代码实现对RabbitMQ的调用. RabbitMQ通常是安装在服 ...
- JAVA-7NIO之Socket/ServerSocket Channel
一.ServerSocketChannel Java NIO中的 ServerSocketChannel 是一个可以监听新进来的TCP连接的通道, 就像标准IO中的ServerSocket一样.Ser ...
- 资料汇总--java开发程序员必备技能
1. 熟练使用Java语言进行面向对象程序设计(面向对象:继承.多态.抽象): 有良好的编程习惯(阿里开发手册 链接:http://pan.baidu.com/s/1dFEA6cT 密码:kqj4 ...
- Visual Basic了解
Visual Basic是一种由微软公司开发的结构化的.模块化的.面向对象的.包含协助开发环境的事件驱动为机制的可视化程序设计语言.这是一种可用于微软自家产品开发的语言.它源自于Basic编程语言.V ...
- Java常见对象之String
String类的概述 String 类代表字符串.Java 程序中的所有字符串字面值(如 "abc" )都作为此类的实例实现.字符串是常量,一旦被赋值,就不能被改变. String ...