ZBar的简单使用
NSRunLoop类声明的编程接口用于管理输入源对象。一个NSRunLoop对象处理像来自窗体系统中的鼠标和键盘事件,NSPORT对象和NSConnection连接对象这类的输入源。一个NSRunLoop对象也处理的NSTimer事件。
每一个NSThread对象。包含应用程序的主线程。具有依据须要自己主动创建一个NSRunLoop对象。假设你须要訪问当前线程的执行循环,能够使用类方法currentRunLoop。
1.下载ZBar的第三方库。加入入project
- (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];
// 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
// 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)
// enable pinch gesture recognition for zooming the preview/decode
// (default YES).
@property (nonatomic) BOOL allowsPinchZoom;
// torch mode to set automatically (default Auto).
// 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
// the region of the image that will be scanned. normalized coordinates.
- (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的简单使用的更多相关文章
- 使用Zbar实现简单的二维码扫描
导入ZBarSDK导入系统库 AVFoundation.framework,CoreMedia.framework,CoreVideo.framework,QuartzCore.framework,l ...
- centos 6.5 python2.6.6 zbar 安装
经过数次折腾,终于搞明白了这个zbar的安装顺序. 1.先安装http://zbar.sourceforge.net/download.html 下的zbar, 2.python 安装z ...
- Zbar算法流程介绍
博客转载自:https://blog.csdn.net/sunflower_boy/article/details/50783179 zbar算法是现在网上开源的条形码,二维码检测算法,算法可识别大部 ...
- 有关python下二维码识别用法及识别率对比分析
最近项目中用到二维码图片识别,在python下二维码识别,目前主要有三个模块:zbar .zbarlight.zxing. 1.三个模块的用法: #-*-coding=utf-8-*- import ...
- iOS ZBar扫码简单实现
导入ZBarSDK文件并引入一下框架 AVFoundation.framework CoreMedia.framework CoreVideo.framework QuartzCore.framewo ...
- 二维码开源库zbar、zxing使用心得
首先说明我的测试场景是“识别打印在纸上的二维码”,在扫描结果中寻找二维码并进行识别,而不是直接让摄像头对着二维码扫描. zbar和zxing用的都是自己从github上clone的c++源码/接口编译 ...
- windows平台python 2.7环境编译安装zbar
最近一个项目需要识别二维码,找来找去找到了zbar和zxing,中间越过无数坑,总算基本上弄明白,分享出来给大家. 一.zbar官方介绍 ZBar 是款桌面电脑用条形码/二维码扫描工具,支持摄像头及图 ...
- ZBar与ZXing使用后感觉
[原]ZBar与ZXing使用后感觉(上) 2014-3-18阅读2011 评论1 最近对二维码比较感兴趣,还是那句老话,那么我就对比了一下zxing和zbar 如果对于这两个的背景不了解的话,可以看 ...
- 编译安装 zbar 时两次 make 带来的惊喜
为了装 php 的条形码扩展模块 php-zbarcode,先装了一天的 ImageMagick 和 zbar.也许和我装的 Ubuntu 17.10 的有版本兼容问题吧,总之什么毛病都有,apt 不 ...
随机推荐
- python脚本11_求10万以内所有素数
#求10万以内所有素数 num = int(input(">>>")) strs = '' for i in range(2,num): for c in ran ...
- 1-11 RHLE7-重定向和文件查找
在Linux 系统中,一切皆设备Linux系统中使用文件来描述各种硬件,设备资源等例如:以前学过的硬盘和分区,光盘等设备文件sda1 sr0============================ ...
- UVALive-4287 Proving Equivalences (有向图的强连通分量)
题目大意:有n个命题,已知其中的m个推导,要证明n个命题全部等价(等价具有传递性),最少还需要做出几次推导. 题目分析:由已知的推导可以建一张无向图,则问题变成了最少需要增加几条边能使图变成强连通图. ...
- Hibernate入门_增删改查
一.Hibernate入门案例剖析: ①创建实体类Student 并重写toString方法 public class Student { private Integer sid; private ...
- 在写一个iOS应用之前必须做的7件事(附相关资源)
本文由CocoaChina--不再犹豫(tao200610704@126.com)翻译 作者:@NIkant Vohra 原文:7 Things you must absolutely do befo ...
- java程序设计基础篇 复习笔记 第四单元
1 think before coding code incrementally 2 sentinel value sentinel-controlled loop 3 输入输出重定向 > &l ...
- bzoj3400
题解: dp f[i][j]表示前i个,膜为j 最后记得判断0 代码: #include<bits/stdc++.h> using namespace std; ; int n,m,a[N ...
- Spring Framework Artifacts
GroupId ArtifactId Description org.springframework spring-aop Proxy-based AOP support org.springfram ...
- Week08《Java程序设计》第八次学习总结
Week08<Java程序设计>第八次学习总结 1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 答: 2.书面作业 1. ArrayList代码分析 1.1 解 ...
- 20165202 预备作业3 Linux安装及学习
一.虚拟机安装 娄老师的<基于VirtualBox安装Ubuntu图文教程>对于安装过程的介绍很易懂,但在安装过程中还是遇到了一些问题 Q1:安装教程中下载地址的VM提示安装包损坏 解决办 ...