[翻译] 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];
}

目录
相关文章
语音平台源码搭建开发之表情功能的实现
语音平台源码搭建开发表情功能对用户不管是语言表达或是体验新歌都是非常重要的,经过一番操作,我们就成功实现了语音平台源码表情功能,后续我会继续为大家分享语音平台源码搭建开发知识。
语音平台源码搭建开发之表情功能的实现
|
6月前
|
图形学
Unity Hololens2开发|(七)MRTK3子系统 TextToSpeechSubsystem(文本转语音)
Unity Hololens2开发|(七)MRTK3子系统 TextToSpeechSubsystem(文本转语音)
|
6月前
|
机器学习/深度学习 算法 数据库
DeepFace【部署 01】轻量级人脸识别和面部属性分析框架deepface安装使用详解(网盘分享模型文件)
DeepFace【部署 01】轻量级人脸识别和面部属性分析框架deepface安装使用详解(网盘分享模型文件)
1273 0
|
文字识别 自然语言处理 Ubuntu
跨平台工具集JamTools:支持截屏、录屏、文字识别、翻译、传输等
一个跨平台的小工具集类软件,支持Windows7/8/10/11、Macos、ubuntu系统(其他系统可以直接从源码编译打包)。包含了(滚动/区域)截屏、录屏、文字识别、多种语言互译、多媒体格式转换、鼠标键盘动作录制播放、局域网文件传输、聊天机器人等功能
2886 0
|
机器学习/深度学习 编解码 测试技术
让移动设备用上轻量级、低延迟的视觉Transformer,苹果搞了个MobileViT
让移动设备用上轻量级、低延迟的视觉Transformer,苹果搞了个MobileViT
168 0
|
机器学习/深度学习 编解码 数据可视化
【超简单】之基于PaddleSpeech语音听写桌面应用
【超简单】之基于PaddleSpeech语音听写桌面应用
489 0
【超简单】之基于PaddleSpeech语音听写桌面应用
|
机器学习/深度学习 数据可视化 语音技术
librosa音频处理教程
librosa音频处理教程
1161 0
librosa音频处理教程
【音频处理】Melodyne 简介 ( Melodyne 音频处理注意事项 | 在音乐宿主软件中加载 Melodyne 插件 )
【音频处理】Melodyne 简介 ( Melodyne 音频处理注意事项 | 在音乐宿主软件中加载 Melodyne 插件 )
569 0
【音频处理】Melodyne 简介 ( Melodyne 音频处理注意事项 | 在音乐宿主软件中加载 Melodyne 插件 )
|
机器学习/深度学习 人工智能 算法
嵌入式端音频开发(Unisound篇)之 7.1 蜂鸟M离线语音芯片简介
嵌入式端音频开发(Unisound篇)之 7.1 蜂鸟M离线语音芯片简介
620 0
嵌入式端音频开发(Unisound篇)之 7.1 蜂鸟M离线语音芯片简介
QT应用编程: 调用系统语音引擎完成文字转语音播报
QT应用编程: 调用系统语音引擎完成文字转语音播报
567 0
下一篇
无影云桌面