使用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编码解码器.条形码的应用已经非常普遍,几乎所有超市里面的商品上面都印有条形码:二维码也开始应用到很多场合,如火车票有二维码识别.网易的首页有二维码图标,用户只需 ...
随机推荐
- python笔记4-遍历文件夹目录os.walk()
前言 如何遍历查找出某个文件夹内所有的子文件呢?并且找出某个后缀的所有文件 walk功能简介 1.os.walk() 方法用于通过在目录树种游走输出在目录中的文件名,向上或者向下. 2.walk()方 ...
- Spring WebSocket入门(二) 转载
本文转载自:http://www.jianshu.com/p/8500ad65eb50 WebSocket前端准备 前端我们需要用到两个js文件:sockjs.js和stomp.js SockJS:S ...
- latex不能识别eps图片
latex中可以使用.eps的图片,许多文档都介绍了怎么引用这种格式的图片,但没有给出使用过程中的注意事项.我在使用MIKTEX的时候,latex文档中引入.eps图片遇到了这样的问题.编译的时候显示 ...
- javascript 中用到的时间戳函数
JavaScript 获取当前时间戳:第一种方法: var timestamp = Date.parse(new Date()); 例如结果:1280977330000第二种方法: var times ...
- CardLayout使用
相对于BoxLayout,GridBugLayut等常用的Swing layout,CardLayout是特殊的,前者是一个容器内布置组件,而后者是在一个容器内放置很多页面(但一个时间只用显示一个). ...
- 在retrofit+Rxjava中如何取得状态码非200(出现错误)时的response里的body
一个典型的retrofit+Rxjava的网络请求如下 Subscription subscription = videoChartService.login(newBody) .observeOn( ...
- CSS 盒状模型简介
框的构成以及相关 CSS 特性( property ) 结构 为了给文档树中的各个元素排版定位(布局),浏览器会根据渲染模型1为每个元素生成四个嵌套的矩形框, 分别称作 content box.pad ...
- E492: Not an editor command: ^M
在windows下拷贝vimrc到Linux,运行vim命令后,出现错误 vim E492: Not an editor command: ^M 原因: linux的文件换行符为\n,但windows ...
- Visual studio之C#实现数字输入模拟键盘
背景 当前做的一个上位机需运行在工控机上,众所周知,工控机不可能配备键盘,只能是触屏,而我当前的上位机需要输入参数,于是之前的解决办法既是调用Windows自带的OSK.exe虚拟键盘,方法在我的另一 ...
- Getting started with Chrome Dev Editor
转自:https://github.com/GoogleChrome/chromedeveditor/blob/master/doc/GettingStarted.md Installation In ...