[翻译] 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 ...
随机推荐
- numpy.linalg.norm(求范数)
1.linalg=linear(线性)+algebra(代数),norm则表示范数. 2.函数参数 x_norm=np.linalg.norm(x, ord=None, axis=None, keep ...
- Hdfs数据备份
Hdfs数据备份 一.概述 本文的hdfs数据备份是在两个集群之间进行的,如果使用snapshot在同一个集群上做备份,如果datanode损坏或误操作清空了数据,这样的备份就无法完全保证数据安全性. ...
- Chrome 谷歌如何快速实现跨域
第一步:在你的E盘或者其他盘新建一个文件夹,命名为:E:\MyChromeDevUserData 第二步:找到你的谷歌浏览器快捷图标,鼠标右键选择属性,出现以下界面: 第三步:在目标选项的最后添加: ...
- Linux IPC机制 - 函数总结
以下表格为IPC的函数总结,IPC包括: 1. 无名管道(Pipe):http://www.cnblogs.com/Jimmy1988/p/7553069.html 2.有名管道(FIFO):http ...
- 《小岛经济学--鱼、美元和经济的故事》Digest
作者:彼得.D.希夫(Peter D. Schiff)安德鲁.J.希(Andrew J. Schiff) How an Economy Grows and Why It Crashes 打车到清华,车 ...
- 扩展jquery插件的方式
- 为Jquery类和Jquery对象扩展方法
转:https://www.cnblogs.com/keyi/p/6089901.html jQuery为开发插件提拱了两个方法,分别是: JavaScript代码 jQuery.fn.extend( ...
- MySQL 批量删除相同前缀的表
sql 命令批量生成drop命令 需要批量删除表,而MySQL又没有提供相关的功能:一般我们建表也都会使用相同前缀,那么,在不使用工具的情况下可以选择使用sql生成批量删除命令: 如删除以 " ...
- vue + element ui 表格自定义表头,提供线上demo
前言:工作中用到 vue+element ui 的前端框架,需要使用自定义表头,需要使用 re.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9710826.h ...
- execution表达式
execution(<修饰符模式>?<返回类型模式><方法名模式>(<参数模式>)<异常模式>?) 除了返回类型模式.方法名模式和参数模式外 ...