维码扫描

2014-06-13 10:20:29|  分类: iOS|举报|字号 订阅

 
 

//

//  TCTosweepScan.m

//  TongChengSearch

//

//  Created by Fighting on 14-6-11.

//  Copyright (c) 2014年 tcsos.com. All rights reserved.

//

#import "TCTosweepScan.h"

#import <AVFoundation/AVFoundation.h>

@interface TCTosweepScan()<AVCaptureMetadataOutputObjectsDelegate>

@property (strong, nonatomic)AVCaptureDevice *device;

@property (strong, nonatomic)AVCaptureDeviceInput *input;

@property (strong, nonatomic)AVCaptureMetadataOutput *output;

@property (strong, nonatomic)AVCaptureSession *session;

@property (strong, nonatomic)AVCaptureVideoPreviewLayer *preview;

@end

@implementation TCTosweepScan

- (instancetype)initConfigWith:(CGRect)frame previewFrame:(CGRect)previewFrame {

if (self = [super init]) {

self.frame = frame;

self.autoresizingMask = YES;

//初始化UI

[self initUI:previewFrame];

}

return self;

}

- (void)dealloc {

// 1. 如果扫描完成,停止会话

[session stopRunning];

// 2. 删除预览图层

[preview removeFromSuperlayer];

[output setMetadataObjectsDelegate:nil queue:nil];

}

//初始化UI

- (void)initUI:(CGRect)previewFrame {

// Device

device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

NSError *error = nil;

// Input

input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];

if (error) {

NSLog(@"你手机不支持二维码扫描!");

return;

}

// Output

output = [[AVCaptureMetadataOutput alloc] init];

[output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];

// Session

session = [[AVCaptureSession alloc] init];

[session setSessionPreset:AVCaptureSessionPresetHigh];

if ([session canAddInput:input]) {

[session addInput:input];

}

if ([session canAddOutput:output]) {

[session addOutput:output];

}

// 条码类型

output.metadataObjectTypes = @[AVMetadataObjectTypeQRCode];

// Preview

preview = [AVCaptureVideoPreviewLayer layerWithSession:session];

preview.videoGravity = AVLayerVideoGravityResizeAspectFill;

preview.frame = previewFrame;

[self.layer addSublayer:preview];

}

//启动扫描

- (void)startScan {

// Start

[session startRunning];

}

// 此方法是在识别到QRCode,并且完成转换

// 如果QRCode的内容越大,转换需要的时间就越长

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection {

// 1. 如果扫描完成,停止会话

[session stopRunning];

// 2. 删除预览图层

[preview removeFromSuperlayer];

NSString *val = nil;

if (metadataObjects.count > 0) {

AVMetadataMachineReadableCodeObject *obj = metadataObjects[0];

val = obj.stringValue;

}

if (delegate && [delegate respondsToSelector:@selector(TCTosweepScanDidEnd:)]) {

[delegate TCTosweepScanDidEnd:val];

}

}

@synthesize delegate;

@synthesize device;

@synthesize input;

@synthesize output;

@synthesize session;

@synthesize preview;

 
 
 
 
 
你好  如何从相册取出图片  进行识别   在iOS7这个框架下  你可以教我一下吗  我的QQ:2315618550   不胜感激
回复
 
 

iOS 7 二维码的更多相关文章

  1. iOS开发-二维码扫描和应用跳转

    iOS开发-二维码扫描和应用跳转   序言 前面我们已经调到过怎么制作二维码,在我们能够生成二维码之后,如何对二维码进行扫描呢? 在iOS7之前,大部分应用中使用的二维码扫描是第三方的扫描框架,例如Z ...

  2. iOS 原生二维码扫描和生成

    代码地址如下:http://www.demodashi.com/demo/12551.html 一.效果预览: 功能描述:WSLNativeScanTool是在利用原生API的条件下封装的二维码扫描工 ...

  3. iOS - QRCode 二维码

    1.QRCode 在 iOS7 以前,在 iOS 中实现二维码和条形码扫描,我们所知的有,两大开源组件 ZBar 与 ZXing. 这两大组件我们都有用过,这里总结下各自的缺点: 1.ZBar 在扫描 ...

  4. IOS开发 二维码功能的实现

    原帖地址:http://yul100887.blog.163.com/blog/static/20033613520121020611299/ 如今二维码随处可见,无论是实物商品还是各种礼券都少不了二 ...

  5. AJ学IOS 之二维码学习,快速打开相机读取二维码

    AJ分享,必须精品 上一篇文章写了怎么生成二维码,这儿就说说怎么读取吧,反正也很简单,iOS封装的太强大了 步骤呢就是这样: 读取二维码需要导入AVFoundation框架#import <AV ...

  6. AJ学IOS 之二维码学习,快速生成二维码

    AJ分享,必须精品 二维码是一项项目中可能会用到的,iOS打开相机索取二维码的速度可不是Android能比的...(Android扫描二维码要来回来回晃...) 简单不多说,如何把一段资料(网址呀,字 ...

  7. iOS 生成二维码

    首先先下载生成二维码的支持文件 libqrencode 添加依赖库 CoreGraphics.framework. QuartzCore.framework.AVFoundation.framewor ...

  8. iOS开发 二维码生成

    基于libqrencode的二维码生成 + (void)drawQRCode:(QRcode *)code context:(CGContextRef)ctx size:(CGFloat)size { ...

  9. iOS开发-二维码的基本使用

    二维码在生活中出现的频率越来越多了,大街小巷各个角落,它的出现更大的作用是代替功能单一的传统条形码,但是通常很多人第一次见到这个都不清楚这是干嘛用的.最初第一次见到可能就是买到的商品上有一个数字的条形 ...

随机推荐

  1. wifi10db定向天线制作及应注意的问题

    2.4GHZ本身就是高频要求制作精度高,如果您动手能力差的话还是不要做的好许多网友看到网上的制作资料就急不可耐的去找材料,然后加班加点的制作.等做出了天线发现效果不怎么样,或出了这样和那样的问题,才肯 ...

  2. TCP粘包的拆包处理

    因为TCP是流式处理的,所以包没有边界,必须设计一个包头,里面表示包的长度(一般用字节表示),根据这个来逐个拆包.如果对于发送/接收频率不高的话,一般也就不做拆包处理了,因为不大可能有粘包现象. 以下 ...

  3. Android中Chronometer 计时器和震动服务控件

    Chronometer 计时器控件 首先在布局文件中添加chronometer控件:然后在mainActivity中获取到该控件 4 然后通过Button时间监听器中开启计时操作 5 chronome ...

  4. [LeetCode] Maximum Gap 解题思路

    Given an unsorted array, find the maximum difference between the successive elements in its sorted f ...

  5. 你应该了解的 7个Linux ls 命令技巧

    在前面我们系列报道的两篇文章中,我们已经涵盖了关于‘ls’命令的绝大多数内容.本文时‘ls命令’系列的最后一部分.如果你还没有读过该系列的其它两篇文章,你可以访问下面的链接. 15 个‘ls’命令的面 ...

  6. 如何右键新建HTML

    直接转载的,原文作者写的很详细:http://blog.csdn.net/ruanjiayou/article/details/51284864 14年在qq日志里写过 2014-10-25  htt ...

  7. Eclipse设置保存时自动给变量加final

    也是针对checkstyle的,在代码检查规范时,所有的变量必须是final.为了解决这个问题,通过以下的设置可以在eclipse保存时,自动给没有加final的变量加上final. Window-& ...

  8. wsdl文件结构分析

    WSDL (Web Services Description Language,Web服务描述语言)是一种XML Application,他将Web服务描述定义为一组服务访问点,客户端可以通过这些服务 ...

  9. 一种调用opencv库的C++工程通用的Makefile模板

    第一次自己写makefile,记录一下 #Compilers #CXX=/opt/compiler/gcc-/bin/g++ CXX = g++ #Includes INCLUDE_FLAGS = - ...

  10. C++沉思录之一

    一.系统跟踪类Trace的设计过程: step1:简单版 class Trace { public: Trace() { noisy = ; } void print(char* s) { if(no ...