[翻译] 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];
}
时间: 2024-09-03 23:20:45

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

视频-急求,大神解答一个定制摄像头问题

问题描述 急求,大神解答一个定制摄像头问题 在iPhone上同时打开前后两个摄像头录制视频能实现嘛?能给个思路吗? 解决方案 连个摄像头都打开这个还算是苹果的专利呢:http://mobile.qudong.com/2013/0830/151841.shtml 解决方案二: 没有试过,但是按照一般思路看来是不能实现的吧 解决方案三: 能不能弄两个控制系统,一个开始前置摄像头,一个控制后面摄像头

百度翻译正式推出手机客户端

百度翻译正式推出手机客户端,现已支持安卓手机平台.据悉,百度翻译iOS版预计在近期也将上线.目前,百度翻译手机客户端1.0版提供中英日文三种语言互译服务,同时是安卓平台上首个支持离线翻译功能的APP. 据了解,百度翻译APP支持离线翻译功能,用户只需下载约35MB大小的"离线翻译包",即可在不联网状态进行翻译.网友"耿意"认为,对于每个月上网流量有限的学生而言,离线翻译功能堪称学习利器,它不受网络限制,同时可节约不少上网流量.业内人士称评测显示百度翻译APP的离线翻

苹果iPhone6s Plus怎么样 iPhone6s Plus值得购买吗?

iPhone6s Plus怎么样 iPhone6s Plus评测详细评测 在苹果公司这几年在华的发展历程中,手机已然成为其业务增长的核心产品.而在如今经济放缓,进出口压力持续增大的环境下,新一代iPhone 6s/6s Plus能否再次刷新业绩成为不少投资者的疑虑之处.相比于往年的产品来说,今年“S”升级版看起来似乎没有太多更新,无论是3D Touch.处理器还是更清晰的拍照,远不如去年屏幕升级带来的视觉冲击,而唯一吸引到用户的或许是全新的玫瑰金配色.看似如此,那实际上iPhone 6s/6s

easyui-Easyui datagrid IE下 行编辑器中控件会随滚动条浮动

问题描述 Easyui datagrid IE下 行编辑器中控件会随滚动条浮动 解决方案 什么版本的easyui?1.4.1没有你说的问题..你的layout是全屏的还是设置了容器而已 解决方案二: 在火狐下无此问题,另外启用行编辑器时候整个行长度会变长一些,这个问题存在于所有浏览器另外 我的datagrid 外面有一层 layout布局. 解决方案三: 申报编号 项目名称 申报单位 协作单位 投资总额 已完成投资额 申报补助额 项目状态 项目内容 width=""70"&q

2016年最佳拍照手机TOP10推荐

TOP 1 三星S7 edge 拍照最强机应该属于三星Note7,但是三星Note7现在已经沦为笑柄,也因此成就了三星S7 edge,S7 edge的摄像头像素为1200万,单像素尺寸达到1.4μm,光圈值更是惊人的F/1.7,在任何条件下都能拍出最出色的照片. 硬件方面,三星Galaxy S7Edge正面采用一块5.5英寸Super AMOLED屏,分辨率为2560x1440像素的Quad HD级别,显示效果细腻依旧.核心方面内置骁龙820处理器,以及4GB RAM LPDDR4运行内存,可流

通过手机上的摄像头,它可以实时翻译各种语言的印刷文字

Word Lens神奇在何处呢?通过手机上的摄像头,它可以实时翻译各种语言的印刷文字.具体原理是这样的:打开手机上的Word Lens,然后将摄像头对准你想翻译的印刷文字,Word Lens 会利用光学字符识别技术(OCR)来识别这些文字,再通过词典进行查找翻译.Word Lens 会利用增强现实技术将翻译过的文字完全覆盖在原有文字上,除语言变了之外,摄像头对着的场景不会发生任何变化.这样一来,你就可以在手机屏幕中看到由翻译结果生成的真实场景.由于词典的辅助,翻译处理无需网络连接就可以在手机本地

手语即时翻译工具,适用所有带摄像头的智能设备

手语即时翻译工具据<每日电讯报>报道,苏格兰研究人员近日宣布,正在开发世界上首款手语即时翻译应用.该应用适用于所有带摄像头的智能设备,包括智能手机.平板和笔记本电脑等.用户只需在摄像头前录下手语手势,该应用便可即时将其翻译成文本,并显示在屏幕上.此外,用户还可拓展手语概念和术语,创建属于自己的词汇库.项目负责人Ernesto Compatangelo表示,该应用将极大地改变5万多个使用英国手语的人,为他们提供便捷的翻译服务,解决沟通障碍.开发人员表示,希望能继续扩展该技术的功能,使其能满足世界

Docker —— 用于统一开发和部署的轻量级 Linux 容器 【已翻译100%】

使用Docker容器--轻量灵活的VM同类,来接管"依赖地狱".学习Docker是如何基于LXC技术,通过把应用包装在容器里来使应用具有移植性和独立性. 想象一下可以轻松地把应用和它的依赖打包,然后在其他的开发.测试和生产环境上平滑的运行.这就是开源Docker项目的目标.尽管它现在还没正式到生产阶段,最新的发布(本篇文章编写时是0.7.x)使得Docker实现这一伟大目标又近了一步. Docker容器试图解决"依赖地狱"问题.现代的应用通常从已存在的组件组合而来,

Adobe为MacBook Air定制轻量级Flash版本

http://www.aliyun.com/zixun/aggregation/9084.html">Adobe的首席执行官Shantanu Narayen本周在Web 2.0峰会透露,公司正在测试一个优化版本的Flash,专门为苹果新发布的MacBook Air打造. Adobe正在考虑改善Flash导致笔记本电池续航时间缩短的问题,主要问题来源于Flash采用了硬件加速,这方面较为耗电,使用Flash的Safari加载网页可使笔记本的续航时间下降高达2小时. 苹果和Adobe在Flas