使用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编码解码器.条形码的应用已经非常普遍,几乎所有超市里面的商品上面都印有条形码:二维码也开始应用到很多场合,如火车票有二维码识别.网易的首页有二维码图标,用户只需 ...
随机推荐
- Julia:高性能 GPU 计算的编程语言
Julia:高性能 GPU 计算的编程语言 0条评论 2017-10-31 18:02 it168网站 原创 作者: 编译|田晓旭 编辑: 田晓旭 [IT168 评论]Julia是一种用于数学计 ...
- Storm常见模式——分布式RPC
Storm常见模式——分布式RPC 本文翻译自:https://github.com/nathanmarz/storm/wiki/Distributed-RPC,作为学习Storm DRPC的资料,转 ...
- Android 将ARGB图片转换为灰度图
思路如下: 1.读取or照相,得到一张ARGB图片. 2.转化为bitmap类,并对其数据做如下操作: A通道保持不变,然后逐像素计算:X = 0.3×R+0.59×G+0.11×B,并使这个像素的值 ...
- ISP图像调试工程师——tone Mapping(ISP)
http://www.cnblogs.com/bigbigtree/p/3458797.html
- ISP图像调试工程师——自动曝光(熟悉3A算法)
基于图像的自动曝光算法研究 : https://wenku.baidu.com/view/c854fa93fd0a79563c1e72ba.html
- Visual Studio2015 简体中文版 安装
VS2015简体中文版安装 导航 介绍 解决安装先决条件 安装 VS2015 创建桌面快捷方式 启动 VS2015 命令启动VS2015 配置 VS2015 启动完成 Visual Studio的功能 ...
- Bitmap和Drawable的互相转换
刚好之前的项目实用到.怕遗忘了.就先记录下来.然后会用到的时候直接来这copy使用就好了. 1.Bitmap ---->Drawable: public static Drawable bitm ...
- iOS程序发布测试-生成ad hoc证书
转自: http://blog.sina.com.cn/s/blog_68444e230100srdn.html iOS程序发布测试3-生成ad hoc证书 iOS证书分2种,1种是开发证书,用来给你 ...
- TX2 ROS IDE开发环境配置
参考资料: http://www.mamicode.com/info-detail-1663827.html 基于Qt搭建ROS开发环境 https://blog.csdn.net/sbtxg/ ...
- win10下Visual Studio 2015,C++ x64编译zmq
PS.本人编译过程踩得坑,记录备忘 下载:(1)官网:http://zeromq.org/intro:get-the-software,有简明的编译方式,cmake的,这里不多赘述 (2)到GitHu ...