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

目录
相关文章
语音平台源码搭建开发之表情功能的实现
语音平台源码搭建开发表情功能对用户不管是语言表达或是体验新歌都是非常重要的,经过一番操作,我们就成功实现了语音平台源码表情功能,后续我会继续为大家分享语音平台源码搭建开发知识。
语音平台源码搭建开发之表情功能的实现
|
5月前
|
机器学习/深度学习 算法 数据库
DeepFace【部署 01】轻量级人脸识别和面部属性分析框架deepface安装使用详解(网盘分享模型文件)
DeepFace【部署 01】轻量级人脸识别和面部属性分析框架deepface安装使用详解(网盘分享模型文件)
1168 0
|
5月前
|
机器学习/深度学习 TensorFlow 语音技术
【Android +Tensroflow Lite】实现从基于机器学习语音中识别指令讲解及实战(超详细 附源码和演示视频)
【Android +Tensroflow Lite】实现从基于机器学习语音中识别指令讲解及实战(超详细 附源码和演示视频)
53 0
|
存储 缓存 iOS开发
iOS 轻量化动态图像下载缓存框架实现
日常开发过程中,图片的下载会占用大量的带宽,图片的加载会消耗大量的性能和内存,正确的使用图片显得尤为重要。 同样也经常需要在各类型控件上读取网络图片和处理本地图片,例如:UIImageView、UIBtton、NSImageView、NSButton等等。
iOS 轻量化动态图像下载缓存框架实现
|
文字识别 自然语言处理 Ubuntu
跨平台工具集JamTools:支持截屏、录屏、文字识别、翻译、传输等
一个跨平台的小工具集类软件,支持Windows7/8/10/11、Macos、ubuntu系统(其他系统可以直接从源码编译打包)。包含了(滚动/区域)截屏、录屏、文字识别、多种语言互译、多媒体格式转换、鼠标键盘动作录制播放、局域网文件传输、聊天机器人等功能
2867 0
|
自然语言处理 Kubernetes 前端开发
5、ChatGPT开源的whisper音频生成字幕,可本地搭建环境运行,效果质量很棒
有五种模型大小,其中四种仅支持英语,提供速度和准确性的权衡。上面便是可用模型的名称、大致的内存需求和相对速度。如果是英文版的语音,直接想转换为英文。
1443 0
|
机器学习/深度学习 人工智能 算法
嵌入式端音频开发(Unisound篇)之 7.1 蜂鸟M离线语音芯片简介
嵌入式端音频开发(Unisound篇)之 7.1 蜂鸟M离线语音芯片简介
611 0
嵌入式端音频开发(Unisound篇)之 7.1 蜂鸟M离线语音芯片简介
|
Web App开发 缓存 算法
白话解读 WebRTC 音频 NetEQ 及优化实践
NetEQ 是 WebRTC 音视频核心技术之一,对于提高 VoIP 质量有明显的效果,本文将从更为宏观的视角,用通俗白话介绍 WebRTC 中音频 NetEQ 的相关概念背景和框架原理,以及相关的优化实践。
白话解读 WebRTC 音频 NetEQ 及优化实践