[翻译] 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 ...
随机推荐
- Impala 使用的端口
下表中列出了 Impala 是用的 TCP 端口.在部署 Impala 之前,请确保每个系统上这些端口都是打开的. 组件 服务 端口 访问需求 备注 Impala Daemon Impala 守护进程 ...
- mysql备份与恢复数据
先备份数据库使用 mysqldump -u root -plvtao 数据库 > /home/bak.sql再把备份的数据库还原就可以了导入数据库 常用source 命令 进入mysql数据库控 ...
- TCP/IP详解学习笔记 这位仁兄写得太好了.(转载)
TCP/IP详解学习笔记 这位仁兄写得太好了 TCP/IP详解学习笔记 这位仁兄写得太好了. http://blog.csdn.net/goodboy1881/category/20444 ...
- Hive导入数据的四种方法
Hive的几种常见的数据导入方式这里介绍四种:(1).从本地文件系统中导入数据到Hive表:(2).从HDFS上导入数据到Hive表:(3).从别的表中查询出相应的数据并导入到Hive表中:(4).在 ...
- 如何获取div距离浏览器顶部的高度,宽度,内容
JS就可以获取了, document.getElementById("DIV的ID或者其它选择").offsetTop;这是离顶部 JQ可以这样: $("#aaa&quo ...
- 结束回调事件(开头必须cp开头,JSProperties传参)
<dx:ASPxComboBox ID="comBrand" CssClass="case" ClientInstanceName="comBr ...
- mybatis之@Select、@Insert、@Delete、@Param
之前学习的时候,看到别人在使用mybatis时,用到@Select.@Insert.@Delete.@Param这几个注解,故楼主研究了一下,在这里与大家分享 当使用这几个注解的时候,可以省去写Map ...
- Emgucv(二)Emgucv和Aforge录制视频
一.Emgucv录制视频 Emgucv中的Capture类可以完成视频文件的读取,利用EmguCV播放视频的原理是:将视频看作图片,用capture获取抓取通道,通过不断的调用{frame = cap ...
- mysql 中 max_allowed_packet 查询和修改
mysql 会根据配置文件限制 server 接收的数据包的大小. 有时候大的插入和更新会被 max_allowed_packet 参数限制,报如下错误: Packet > ). You can ...
- fzu 2163
Problem 2163 多米诺骨牌 Accept: 17 Submit: 50Time Limit: 1000 mSec Memory Limit : 32768 KB Problem ...