使用ZBar来读取条形码和二维码的方法
版权声明:本文为博主原创文章,未经博主允许不得转载。
1.使用ZBar项目。下载地址是: http://zbar.sourceforge.net/iphone/index.html
2.新建一个项目。
3.导入 ZBar的sdk。把ZBar SDK的目录拉入项目,然后选中copy选项
4.在项目文件的target中加入 以下framework
5.在appDelegate文件中加入 标记部分的代码
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
- // Override point for customization after application launch.
- self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
- self.window.rootViewController = self.viewController;
- [self.window makeKeyAndVisible];
- // force view class to load so it may be referenced directly from NIB
- [ZBarReaderView class];
- return YES;
- }
注意此代码:
- // force view class to load so it may be referenced directly from NIB
- [ZBarReaderView class];
6.在.h文件中加入 ZBarReaderViewDelegate的实现,代码如下:
- //
- // ViewController.h
- // FootSafety
- //
- // Created by 泽宇 徐 on 12-6-12.
- // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
- //
- #import <UIKit/UIKit.h>
- #import "ZBarSDK.h"
- @interface ViewController : UIViewController<ZBarReaderViewDelegate>
- {
- IBOutlet UILabel * label ;
- ZBarReaderView *readerView;
- ZBarCameraSimulator *cameraSim;
- }
- @property(nonatomic,retain) UILabel * label ;
- @property (nonatomic, retain) IBOutlet ZBarReaderView *readerView;
- @end
7.在.m文件中要实现的主要方法是:
- - (void) readerView: (ZBarReaderView*) view
- didReadSymbols: (ZBarSymbolSet*) syms
- fromImage: (UIImage*) img
- {
- // do something useful with results
- for(ZBarSymbol *sym in syms) {
- self.label.text = sym.data;
- break;
- }
- }
这里是功能是读取照片信息,把条码放如label显示
- -(void) viewDidAppear:(BOOL)animated
- {
- // run the reader when the view is visible
- [readerView start];
- }
这个是在显示视图的时候,启动摄像头,开始扫描
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- // the delegate receives decode results
- readerView.readerDelegate = self;
- // you can use this to support the simulator
- if(TARGET_IPHONE_SIMULATOR) {
- cameraSim = [[ZBarCameraSimulator alloc]
- initWithViewController: self];
- cameraSim.readerView = readerView;
- }
- }
在初始化的时候,设置托管。
.m文件所有内容是:
- //
- // ViewController.m
- // FootSafety
- //
- // Created by 泽宇 徐 on 12-6-12.
- // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
- //
- #import "ViewController.h"
- @interface ViewController ()
- @end
- @implementation ViewController
- @synthesize label;
- @synthesize readerView;
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- // the delegate receives decode results
- readerView.readerDelegate = self;
- // you can use this to support the simulator
- if(TARGET_IPHONE_SIMULATOR) {
- cameraSim = [[ZBarCameraSimulator alloc]
- initWithViewController: self];
- cameraSim.readerView = readerView;
- }
- }
- -(void) viewDidAppear:(BOOL)animated
- {
- // run the reader when the view is visible
- [readerView start];
- }
- - (void) readerView: (ZBarReaderView*) view
- didReadSymbols: (ZBarSymbolSet*) syms
- fromImage: (UIImage*) img
- {
- // do something useful with results
- for(ZBarSymbol *sym in syms) {
- self.label.text = sym.data;
- break;
- }
- }
- - (void)viewDidUnload
- {
- [super viewDidUnload];
- // Release any retained subviews of the main view.
- }
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- {
- return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
- }
- -(void) dealloc
- {
- [self.readerView release];
- [self.label release];
- [super dealloc];
- }
- @end
在ViewController.xib文件中 增加一个view,并且修改view的类是ZBarReaderView ,并且指向 .h文件中定义的
- ZBarReaderView *readerView;
版权声明:本文为博主原创文章,未经博主允许不得转载。 .使用ZBar项目。下载地址是: http://zbar.sourceforge.net/iphone/index.html .新建一个项目。 .导入 ZBar的sdk。把ZBar SDK的目录拉入项目,然后选中copy选项 .在项目文件的target中加入 以下framework .在appDelegate文件中加入 标记部分的代码
[cpp] view plain copy
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible]; // force view class to load so it may be referenced directly from NIB
[ZBarReaderView class]; return YES;
}
注意此代码: [cpp] view plain copy
// force view class to load so it may be referenced directly from NIB
[ZBarReaderView class]; .在.h文件中加入 ZBarReaderViewDelegate的实现,代码如下:
[cpp] view plain copy
//
// ViewController.h
// FootSafety
//
// Created by 泽宇 徐 on 12-6-12.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
// #import <UIKit/UIKit.h>
#import "ZBarSDK.h" @interface ViewController : UIViewController<ZBarReaderViewDelegate>
{
IBOutlet UILabel * label ;
ZBarReaderView *readerView;
ZBarCameraSimulator *cameraSim;
} @property(nonatomic,retain) UILabel * label ;
@property (nonatomic, retain) IBOutlet ZBarReaderView *readerView; @end .在.m文件中要实现的主要方法是: [html] view plain copy
- (void) readerView: (ZBarReaderView*) view
didReadSymbols: (ZBarSymbolSet*) syms
fromImage: (UIImage*) img
{
// do something useful with results
for(ZBarSymbol *sym in syms) {
self.label.text = sym.data;
break;
}
} 这里是功能是读取照片信息,把条码放如label显示 [html] view plain copy
-(void) viewDidAppear:(BOOL)animated
{
// run the reader when the view is visible
[readerView start];
} 这个是在显示视图的时候,启动摄像头,开始扫描 [html] view plain copy
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. // the delegate receives decode results
readerView.readerDelegate = self; // you can use this to support the simulator
if(TARGET_IPHONE_SIMULATOR) {
cameraSim = [[ZBarCameraSimulator alloc]
initWithViewController: self];
cameraSim.readerView = readerView;
} } 在初始化的时候,设置托管。 .m文件所有内容是:
[html] view plain copy
//
// ViewController.m
// FootSafety
//
// Created by 泽宇 徐 on 12-6-12.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
// #import "ViewController.h" @interface ViewController () @end @implementation ViewController
@synthesize label;
@synthesize readerView; - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. // the delegate receives decode results
readerView.readerDelegate = self; // you can use this to support the simulator
if(TARGET_IPHONE_SIMULATOR) {
cameraSim = [[ZBarCameraSimulator alloc]
initWithViewController: self];
cameraSim.readerView = readerView;
} } -(void) viewDidAppear:(BOOL)animated
{
// run the reader when the view is visible
[readerView start];
} - (void) readerView: (ZBarReaderView*) view
didReadSymbols: (ZBarSymbolSet*) syms
fromImage: (UIImage*) img
{
// do something useful with results
for(ZBarSymbol *sym in syms) {
self.label.text = sym.data;
break;
}
} - (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
} - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} -(void) dealloc
{
[self.readerView release];
[self.label release];
[super dealloc];
} @end 在ViewController.xib文件中 增加一个view,并且修改view的类是ZBarReaderView ,并且指向 .h文件中定义的
[cpp] view plain copy
ZBarReaderView *readerView;
使用ZBar来读取条形码和二维码的方法的更多相关文章
- Java生成读取条形码和二维码图片
原文:http://www.open-open.com/code/view/1453520722495 package zxing; import com.google.zxing.BarcodeFo ...
- zbar+opencv检测图片中的二维码或条形码
zbar本身自带检测二维码条形码功能,这里使用opencv只是做一些简单的读取图片,灰度图片以及显示条形码和二维码时用到一些绘制 // barcode-qrcodescanner.cpp: 定义控制台 ...
- [转]用C#实现的条形码和二维码编码解码器
条形码的标准: 条形码的标准有ENA条形码.UPC条形码.二五条形码.交叉二五条形码.库德巴条形码.三九条形码和128条形码等,而商品上最常使用的就是EAN商品条形码.EAN商品条形码亦称通用商品条形 ...
- 基于opencv3.0和下的条形码与二维码识别
其中对条码与二维码的识别分为以下4个步骤 1. 利用opencv和Zbar(或者Zxing)对标准的条形码图片(即没有多余背景干扰,且图片没有倾斜)进行解码,将解码信息显示出来,并与原始信息对比. 2 ...
- Android之条形码、二维码扫描框架(非原创)
文章大纲 一.条形码.二维码扫描框架介绍二.条形码.二维码的区别和组成结构介绍三.条形码.二维码扫描框架应用场景四.BGAQRCode-Android框架实战五.项目源码下载六.参考文章 一.条形码. ...
- Java 创建/识别条形码、二维码
条形码(Barcode)是将宽度不等的多个黑条和空白,按照一定的编码规则排列,用以表达一组信息的图形标识符.常用于标示物品的生产国.制造厂家.商品名称.生产日期.图书分类号.邮件起止地点.类别.日期等 ...
- (整理).net实现条形码与二维码
本文由来源网络的知识点组合而成,感谢分享的作者,文章结尾处给出查询资料连接. 条形码(barcode)是将宽度不等的多个黑条和空白,按照一定的编码规则排列,用以表达一组信息的图形标识符.常见的条形码是 ...
- 实例源码--ZXing识别条形码和二维码识别源码
下载源码 技术要点: 1.ZXing库的 使用 2.识别条形码和二 维码 3.自定义视图 4.源码带有非常详 细的中文注释 ...... 详细介绍: 1.ZXing库 ZXing是个很经典的条码/ ...
- 用C#实现的条形码和二维码编码解码器
本文主要介绍可以在C#中使用的1D/2D编码解码器.条形码的应用已经非常普遍,几乎所有超市里面的商品上面都印有条形码:二维码也开始应用到很多场合,如火车票有二维码识别.网易的首页有二维码图标,用户只需 ...
随机推荐
- JS中for和forEach的区别
https://thejsguy.com/2016/07/30/javascript-for-loop-vs-array-foreach.html
- 【转载】【Todo】银弹与我们的职业
看到一段文字,不得不单独拎出来. 然后再借用一下g9老大的<银弹和我们的职业>中的话: 银弹和我们的职业发展有什么相干?很简单:我们得把时间用于学习解决本质困难.新技术给高手带来方便.菜鸟 ...
- django admin后台接入tinymce并且支持图片上传
首先:下载tinymce 地址是https://www.tinymce.com/ 点击download 下载社区版本即可 接着:把压缩包内tinymce目录内的所有文件和文件夹复制到Django项目中 ...
- Because, since, as, for
because, as, for, since这几个词都是表示“原因”的连词,语气由强至弱依次为:because→since→as→for;其中because, since, as均为从属连词,引导原 ...
- BST数据结构题
给定BST.改动BST,使得每一个点都是大于他的结点的值之和 关键是这题递归參数怎么设计,每一个点比他大的有两快.一个是右子书(假设有的话),还有一个是祖先里面比他大的,假设直接用这两个的话,找不到递 ...
- tomcat通过虚拟路径访问外部静态资源
转载:http://blog.csdn.net/yuancenyi/article/details/53414397 在项目开发中,单个工程中,为了以后软件版本升级的方便,经常将网站运行中某些上传的静 ...
- X5平方速算法的证明
X5代表15,25,35,45,55......以上变化的部分为X,如25这个数,X就等于2. X5平方数的速算法是这样:让X乘以X+1,后面写上25就是X5乘以X5的结果.比如25x25,先让2x3 ...
- poj 2253 (dis最短路径)
Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 24979 Accepted: 8114 Descript ...
- APNS .p12文件转换为 .pem文件
1:先用mac的钥匙串工具,把APN的推送证书转换为 .p12文件: 2:在mac的终端下 把.p12文件转换为 .pem文件 openssl pkcs12 -in apns-dev-cert.p12 ...
- silverlight客户端保存文件乱码问题
最近做一个项目,有一个需求是这样的:服务端从数据库里获得数据,客户端保存为Excel文件 最初解决方案:服务端获得数据,通过ExcelPackage,Convert.ToBase64String将by ...