NSRunLoop类声明的编程接口用于管理输入源对象。一个NSRunLoop对象处理像来自窗体系统中的鼠标和键盘事件,NSPORT对象和NSConnection连接对象这类的输入源。一个NSRunLoop对象也处理的NSTimer事件。

你的应用程序不能建立或明白管理NSRunLoop对象。

每一个NSThread对象。包含应用程序的主线程。具有依据须要自己主动创建一个NSRunLoop对象。假设你须要訪问当前线程的执行循环,能够使用类方法currentRunLoop。

1.下载ZBar的第三方库。加入入project

2.加入相关库
   AVFoundation.framework
   CoreMedia.framework
   CoreVideo.framework
   libiconv.2.4.0.dylib  
3.添加一个以ZBarReaderViewController为父类的控制器。并实现ZBarReaderDelegate代理
4.在控制器中加入例如以下代码
条形码的扫描

- (void)viewDidLoad
{
    [super viewDidLoad];
    //设置代理
    self.readerDelegate = self;
    //扫瞄图像
    ZBarImageScanner *mScanner = self.scanner;
    //是否显示绿色的追踪框。注意。即当选择yes的时候。这个框只当扫瞄EAN和I2/5的时候才可见。

    self.tracksSymbols = YES;
    //是否使用备用控制组
    self.showsZBarControls = YES;
    //支持的方向。用ZBarOrientationMask() 和 ZBarOrientationMaskAll
    self.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationMaskPortrait);
    
    //提供自己定义覆盖层。注意,在showsZBarControls启用的情况下才干够用
    UIView *view = [[UIView alloc] initWithFrame:self.view.bounds];
    view.backgroundColor = [UIColor grayColor];
    self.cameraOverlayView = view;
    
    //裁剪扫描的图像,在扫描前图像将被裁剪到这个矩形内。这个矩形框是将图像的尺寸和宽高比标准化,
    //有效值将放置矩形内介于0和1的每一个轴。当中x轴相应于图像的长轴。默觉得完整的图像(0。0,1,1)。

//    self.scanCrop
    //调节以适应预览图片
//    self.cameraViewTransform

     //解码配置
    [mScanner setSymbology:ZBAR_I25
                   config:ZBAR_CFG_ENABLE
                       to:0];
// Do any additional setup after loading the view.
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self.readerView start];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.readerView stop];
}

- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    //获取扫瞄结果
    id<NSFastEnumeration>
results = [info objectForKey:ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;

     //不过抓住第一个条形码
    for (symbol in results)
        break;
    NSString *text = symbol.data;
        //解决中文乱码问题
    if ([text canBeConvertedToEncoding:NSShiftJISStringEncoding])
{
        text = [NSString stringWithCString:[text cStringUsingEncoding:NSShiftJISStringEncoding] encoding:NSUTF8StringEncoding];
    }
    NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[NSString stringWithFormat:@"%@",text],@"resultLabel",[info objectForKey:UIImagePickerControllerOriginalImage],@"resultImgView", nil];
    [self performSelectorOnMainThread:@selector(mainAction:) withObject:dic waitUntilDone:NO];
}

- (void)mainAction:(NSDictionary *)dic
{
    OtherViewController *other = [[OtherViewController alloc] init];
    other.resultString = [dic objectForKey:@"resultLabel"];
    other.image = [dic objectForKey:@"resultImgView"];
    [self.navigationController pushViewController:other animated:YES];

}
此时,我们再来看看ZBarReaderViewController中的ZBarReaderView这个类

// supply a pre-configured image scanner.

//支持一个预先准备的图片扫描
- (id) initWithImageScanner: (ZBarImageScanner*)
imageScanner;

// start the video stream and barcode reader.

//開始视频流和条形码扫描
- (void) start;

// stop the video stream and barcode reader.

//停止视频流和条形码扫描
- (void) stop;

// clear the internal result cache

//清理内部的缓存
- (void) flushCache;

// compensate for device/camera/interface orientation

// 适应设备的方向
- (void) willRotateToInterfaceOrientation: (UIInterfaceOrientation)
orient

                                 duration: (NSTimeInterval) duration;

// delegate is notified of decode results.

//代理
@property (nonatomic, assign) id<ZBarReaderViewDelegate>
readerDelegate;

// access to image scanner for configuration.

//直接对图片扫描配置
@property (nonatomic, readonly) ZBarImageScanner *scanner;

// whether to display the tracking annotation for uncertain barcodes
// (default YES).

// 是否为不确定的条形码显示追踪
@property (nonatomic) BOOL tracksSymbols;

// color of the tracking box (default green)

//追踪框的颜色,默觉得绿色

@property (nonatomic, retain) UIColor *trackingColor;

// enable pinch gesture recognition for zooming the preview/decode
// (default YES).

// 能否对预览图进行手势缩放,默认是能够的
@property (nonatomic) BOOL allowsPinchZoom;

// torch mode to set automatically (default Auto).

// 0为不闪光。1为闪光

@property (nonatomic) NSInteger torchMode;

// zoom scale factor applied to video preview *and* scanCrop.
// also updated by pinch-zoom gesture.  clipped to range [1,maxZoom],
// defaults to 1.25

// 施加于摄像前景画面和扫描区域的缩放
@property (nonatomic) CGFloat zoom;
- (void) setZoom: (CGFloat) zoom

        animated: (BOOL) animated;

// the region of the image that will be scanned.  normalized coordinates.

// 图片将被扫描的区域,标准坐标

@property (nonatomic) CGRect scanCrop;
二维码的扫描
实现代理ZBarReaderViewDelegate

- (void)readerView:(ZBarReaderView *)readerView
didReadSymbols:(ZBarSymbolSet *)symbols fromImage:(UIImage *)image
{
    ZBarSymbol *symbol = nil;
    for (symbol in symbols)
        break;
    NSString *text = symbol.data;
    NSLog(@"%@",text);

}

ZBar的简单使用的更多相关文章

  1. 使用Zbar实现简单的二维码扫描

    导入ZBarSDK导入系统库 AVFoundation.framework,CoreMedia.framework,CoreVideo.framework,QuartzCore.framework,l ...

  2. centos 6.5 python2.6.6 zbar 安装

       经过数次折腾,终于搞明白了这个zbar的安装顺序.   1.先安装http://zbar.sourceforge.net/download.html 下的zbar,   2.python 安装z ...

  3. Zbar算法流程介绍

    博客转载自:https://blog.csdn.net/sunflower_boy/article/details/50783179 zbar算法是现在网上开源的条形码,二维码检测算法,算法可识别大部 ...

  4. 有关python下二维码识别用法及识别率对比分析

    最近项目中用到二维码图片识别,在python下二维码识别,目前主要有三个模块:zbar .zbarlight.zxing. 1.三个模块的用法: #-*-coding=utf-8-*- import ...

  5. iOS ZBar扫码简单实现

    导入ZBarSDK文件并引入一下框架 AVFoundation.framework CoreMedia.framework CoreVideo.framework QuartzCore.framewo ...

  6. 二维码开源库zbar、zxing使用心得

    首先说明我的测试场景是“识别打印在纸上的二维码”,在扫描结果中寻找二维码并进行识别,而不是直接让摄像头对着二维码扫描. zbar和zxing用的都是自己从github上clone的c++源码/接口编译 ...

  7. windows平台python 2.7环境编译安装zbar

    最近一个项目需要识别二维码,找来找去找到了zbar和zxing,中间越过无数坑,总算基本上弄明白,分享出来给大家. 一.zbar官方介绍 ZBar 是款桌面电脑用条形码/二维码扫描工具,支持摄像头及图 ...

  8. ZBar与ZXing使用后感觉

    [原]ZBar与ZXing使用后感觉(上) 2014-3-18阅读2011 评论1 最近对二维码比较感兴趣,还是那句老话,那么我就对比了一下zxing和zbar 如果对于这两个的背景不了解的话,可以看 ...

  9. 编译安装 zbar 时两次 make 带来的惊喜

    为了装 php 的条形码扩展模块 php-zbarcode,先装了一天的 ImageMagick 和 zbar.也许和我装的 Ubuntu 17.10 的有版本兼容问题吧,总之什么毛病都有,apt 不 ...

随机推荐

  1. slim(4621✨)

    用于代码瘦身. 老鸟建议:不要混写js 和 html,如果避免不了,当前文件可以改为erb格式,混用slim和erb不是什么问题. git:  https://github.com/slim-temp ...

  2. oom_killer

    Limited Memory 今天在虚拟机里面用Word处理文档的时候,突然硬盘灯一阵狂闪,然后虚拟机就一起消失了. 这种事情屡见不鲜,很明显是Linux内核把占用最多内存的程序(这次是Virtual ...

  3. [nodejs]解决mysql和连接池(pool)自动断开问题

    最近在做一个个人项目,数据库尝试使用了mongodb.sqlite和mysql.分享一下关于mysql的连接池用法.项目部署于appfog,项目中我使用连接池链接数据库,本地测试一切正常.上线以后,经 ...

  4. Spring Boot配置ContextPath【从零开始学Spring Boot】

    Spring boot默认是/ ,这样直接通过http://ip:port/就可以访问到index页面,如果要修改为http://ip:port/path/ 访问的话,那么需要在Application ...

  5. python:input()和raw_input()

    1.input() 接受各种合法类型的输入,比如输入字符串,则需要使用双引号,否则报错. input()会自动判断类型,比如输入的是 1.1,则返回的类型是float. 示例: 2.raw_input ...

  6. C++复习12.程序内存管理

    程序内存管理 20131006 一个程序在运行期间的内存是如何的对编写程序至关重要,之前整理的C++内存管理的知识和Java程序内存管理的知识.今天我们系统的整理一下程序的内存. 1.一个程序的内存有 ...

  7. javascript 事件委托 event delegation

    事件委托 event delegation 一.概念: 假设我们有很多个子元素,每个元素被点击时都会触发相应事件,普通的做法是给每个子元素添加一个事件监听. 而,事件委托则是给它们的父元素添加一个事件 ...

  8. gradle 删除指定目录中的文件和目录

    // 删除bakAPk下的所有非母包文件 task deleTask(type: Delete){ FileTree tree = fileTree(dir: bakPath) tree.each { ...

  9. 解决chrome报Not allowed to load local resource错误的方法

    最近项目中遇到了关于图片的更改->保存->本地读取 在本地读取的环节上面出现了错误,一开始用的是直接本地路径,但是在页面上调试的出现了下面的错误,他的路径还是相对路径,下图所示: Goog ...

  10. vue.js 源代码学习笔记 ----- 工具方法 error

    import config from '../config' import { warn } from './debug' import { inBrowser } from './env' // 这 ...