版权声明:本文为博主原创文章,未经博主允许不得转载。

1.使用ZBar项目。下载地址是: http://zbar.sourceforge.net/iphone/index.html

2.新建一个项目。

3.导入 ZBar的sdk。把ZBar SDK的目录拉入项目,然后选中copy选项

4.在项目文件的target中加入 以下framework

5.在appDelegate文件中加入 标记部分的代码

  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  2. {
  3. self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
  4. // Override point for customization after application launch.
  5. self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
  6. self.window.rootViewController = self.viewController;
  7. [self.window makeKeyAndVisible];
  8. // force view class to load so it may be referenced directly from NIB
  9. [ZBarReaderView class];
  10. return YES;
  11. }

注意此代码:

  1. // force view class to load so it may be referenced directly from NIB
  2. [ZBarReaderView class];

6.在.h文件中加入   ZBarReaderViewDelegate的实现,代码如下:

  1. //
  2. //  ViewController.h
  3. //  FootSafety
  4. //
  5. //  Created by 泽宇 徐 on 12-6-12.
  6. //  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import "ZBarSDK.h"
  10. @interface ViewController : UIViewController<ZBarReaderViewDelegate>
  11. {
  12. IBOutlet UILabel  * label ;
  13. ZBarReaderView *readerView;
  14. ZBarCameraSimulator *cameraSim;
  15. }
  16. @property(nonatomic,retain) UILabel * label ;
  17. @property (nonatomic, retain) IBOutlet ZBarReaderView *readerView;
  18. @end

7.在.m文件中要实现的主要方法是:

  1. - (void) readerView: (ZBarReaderView*) view
  2. didReadSymbols: (ZBarSymbolSet*) syms
  3. fromImage: (UIImage*) img
  4. {
  5. // do something useful with results
  6. for(ZBarSymbol *sym in syms) {
  7. self.label.text = sym.data;
  8. break;
  9. }
  10. }

这里是功能是读取照片信息,把条码放如label显示

  1. -(void) viewDidAppear:(BOOL)animated
  2. {
  3. // run the reader when the view is visible
  4. [readerView start];
  5. }

这个是在显示视图的时候,启动摄像头,开始扫描

  1. - (void)viewDidLoad
  2. {
  3. [super viewDidLoad];
  4. // Do any additional setup after loading the view, typically from a nib.
  5. // the delegate receives decode results
  6. readerView.readerDelegate = self;
  7. // you can use this to support the simulator
  8. if(TARGET_IPHONE_SIMULATOR) {
  9. cameraSim = [[ZBarCameraSimulator alloc]
  10. initWithViewController: self];
  11. cameraSim.readerView = readerView;
  12. }
  13. }

在初始化的时候,设置托管。

.m文件所有内容是:

  1. //
  2. //  ViewController.m
  3. //  FootSafety
  4. //
  5. //  Created by 泽宇 徐 on 12-6-12.
  6. //  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
  7. //
  8. #import "ViewController.h"
  9. @interface ViewController ()
  10. @end
  11. @implementation ViewController
  12. @synthesize label;
  13. @synthesize readerView;
  14. - (void)viewDidLoad
  15. {
  16. [super viewDidLoad];
  17. // Do any additional setup after loading the view, typically from a nib.
  18. // the delegate receives decode results
  19. readerView.readerDelegate = self;
  20. // you can use this to support the simulator
  21. if(TARGET_IPHONE_SIMULATOR) {
  22. cameraSim = [[ZBarCameraSimulator alloc]
  23. initWithViewController: self];
  24. cameraSim.readerView = readerView;
  25. }
  26. }
  27. -(void) viewDidAppear:(BOOL)animated
  28. {
  29. // run the reader when the view is visible
  30. [readerView start];
  31. }
  32. - (void) readerView: (ZBarReaderView*) view
  33. didReadSymbols: (ZBarSymbolSet*) syms
  34. fromImage: (UIImage*) img
  35. {
  36. // do something useful with results
  37. for(ZBarSymbol *sym in syms) {
  38. self.label.text = sym.data;
  39. break;
  40. }
  41. }
  42. - (void)viewDidUnload
  43. {
  44. [super viewDidUnload];
  45. // Release any retained subviews of the main view.
  46. }
  47. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  48. {
  49. return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
  50. }
  51. -(void) dealloc
  52. {
  53. [self.readerView release];
  54. [self.label release];
  55. [super dealloc];
  56. }
  57. @end

在ViewController.xib文件中 增加一个view,并且修改view的类是ZBarReaderView ,并且指向 .h文件中定义的

  1. 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来读取条形码和二维码的方法的更多相关文章

  1. Java生成读取条形码和二维码图片

    原文:http://www.open-open.com/code/view/1453520722495 package zxing; import com.google.zxing.BarcodeFo ...

  2. zbar+opencv检测图片中的二维码或条形码

    zbar本身自带检测二维码条形码功能,这里使用opencv只是做一些简单的读取图片,灰度图片以及显示条形码和二维码时用到一些绘制 // barcode-qrcodescanner.cpp: 定义控制台 ...

  3. [转]用C#实现的条形码和二维码编码解码器

    条形码的标准: 条形码的标准有ENA条形码.UPC条形码.二五条形码.交叉二五条形码.库德巴条形码.三九条形码和128条形码等,而商品上最常使用的就是EAN商品条形码.EAN商品条形码亦称通用商品条形 ...

  4. 基于opencv3.0和下的条形码与二维码识别

    其中对条码与二维码的识别分为以下4个步骤 1. 利用opencv和Zbar(或者Zxing)对标准的条形码图片(即没有多余背景干扰,且图片没有倾斜)进行解码,将解码信息显示出来,并与原始信息对比. 2 ...

  5. Android之条形码、二维码扫描框架(非原创)

    文章大纲 一.条形码.二维码扫描框架介绍二.条形码.二维码的区别和组成结构介绍三.条形码.二维码扫描框架应用场景四.BGAQRCode-Android框架实战五.项目源码下载六.参考文章 一.条形码. ...

  6. Java 创建/识别条形码、二维码

    条形码(Barcode)是将宽度不等的多个黑条和空白,按照一定的编码规则排列,用以表达一组信息的图形标识符.常用于标示物品的生产国.制造厂家.商品名称.生产日期.图书分类号.邮件起止地点.类别.日期等 ...

  7. (整理).net实现条形码与二维码

    本文由来源网络的知识点组合而成,感谢分享的作者,文章结尾处给出查询资料连接. 条形码(barcode)是将宽度不等的多个黑条和空白,按照一定的编码规则排列,用以表达一组信息的图形标识符.常见的条形码是 ...

  8. 实例源码--ZXing识别条形码和二维码识别源码

      下载源码 技术要点: 1.ZXing库的 使用 2.识别条形码和二 维码 3.自定义视图 4.源码带有非常详 细的中文注释 ...... 详细介绍: 1.ZXing库 ZXing是个很经典的条码/ ...

  9. 用C#实现的条形码和二维码编码解码器

    本文主要介绍可以在C#中使用的1D/2D编码解码器.条形码的应用已经非常普遍,几乎所有超市里面的商品上面都印有条形码:二维码也开始应用到很多场合,如火车票有二维码识别.网易的首页有二维码图标,用户只需 ...

随机推荐

  1. meteor学习-- #一 安装meteor快速使用

    下载安装 curl https://install.meteor.com/ | sh meteor会自动下载mongodb和其他需要依赖的库,不需要手动安装. 如果是Windows 的用户,请使用 m ...

  2. 客户端Git的常用命令

    (1)git clone 服务器用户名@服务器IP:~/Git目录/.git 功能:下载服务器端Git仓库中的文件或目录到本地当前目录. (2)git status 功能:查看Git仓库中的文件状态. ...

  3. PL/SQL如何远程连接ORACLE

    如何在没有装ORACLE的电脑上用PLSQL远程连接ORACLE 下载instantclient,我的是WIN7,下载的是instantclient-basiclite-nt-12.1.0.1.0.z ...

  4. [ES6] 07. Default Value for function param

    Normally, we can set default value for function param: //Here use "Hello" as default param ...

  5. javascript设置首页,加入收藏

    <a href="javascript:;" id="setHomePage" class="toolsbar" onclick=&q ...

  6. COSMOSBOX手遊制作手册(Word备份)

    20140712版 版本号 Version 日期 Date 作者 Author 变更主要原因描述 Brief Description 1.0 2014-4-26 陈霈霖 初稿 2.0 1. 前言 本手 ...

  7. 二维纹理 Texture 2D

    Textures bring your Meshes, Particles, and interfaces to life! They are image or movie files that yo ...

  8. SQL-ORDER BY 多字段排序(升序、降序)

    ORDER BY _column1, _column2; /* _column1升序,_column2升序 */   ORDER BY _column1, _column2 DESC; /* _col ...

  9. python xml.etree.ElementTree解析xml文件获取节点

    <?xml version = "1.0" encoding = "utf-8"?> <root> <body name=&quo ...

  10. IOS Exception 1(libc++abi.dylib: terminating with uncaught exception of type NSException)

    2014-08-05 22:18:46.455 SwiftUI[1329:40871] -[_TtC7SwiftUI14MViewControler clickMe]: unrecognized se ...