iOS 二维码扫面 相册图片二维码读取和二维码的生成

1,二维码扫面用ios7 自带控件

@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;


 if ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]==AVAuthorizationStatusDenied) {
        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"未能调用相机,请检查“设置->隐私->相机”是否打开" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alert show];
        return;
    }
    self.device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    self.input = [AVCaptureDeviceInput deviceInputWithDevice:self.device error:nil];
    self.output = [[AVCaptureMetadataOutput alloc]init];
    [self.output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
    //[self.output setRectOfInterest:CGRectMake((124)/ScreenHeight,((ScreenWidth-220)/2)/ScreenWidth,220/ScreenHeight,220/ScreenWidth)];
    self.session = [[AVCaptureSession alloc]init];
    if ([self.session canAddInput:self.input]) {
        [self.session addInput:self.input];
    }
    if ([self.session canAddOutput:self.output]) {
        [self.session addOutput:self.output];
    }
    self.output.metadataObjectTypes = @[AVMetadataObjectTypeQRCode];
    self.preview = [AVCaptureVideoPreviewLayer layerWithSession:self.session];
    self.preview.videoGravity = AVLayerVideoGravityResizeAspectFill;
    self.preview.frame = self.view.layer.bounds;
    [self.view.layer insertSublayer:self.preview atIndex:0];
    [self.session startRunning];
//回调函数
#pragma mark avcapturemetadataoutputobjectsdelegate
-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection
{
    NSString * stringvalue;
    if ([metadataObjects count]>0) {
        [self.session stopRunning];
        AVMetadataMachineReadableCodeObject * metadataObject = [metadataObjects objectAtIndex:0];
        stringvalue = metadataObject.stringValue;
        NSLog(@"qrcode=%@",stringvalue);
    }
    NSLog(@"qrcodeOK");
    [self.delegate KBErweimaFinishWithString:stringvalue];//对数据进行处理的 delegate 
    [self.navigationController popViewControllerAnimated:YES];
}
2相册图片的二维码解析      http://download.csdn.net/detail/zyq527758142/8428825     64位 zbar 下载地址  记得引入 lib icon.dylib  库
#pragma mark-调用相册二维码
-(void)photoErwei{
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
    {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        picker.delegate = self;
        
        picker.allowsEditing = YES;
        [self presentModalViewController:picker animated:YES];
    }else{
        NSLog(@"相册不能用。。。");
    }
    

}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

    ZBarReaderController* read = [ZBarReaderController new];

    read.readerDelegate = self;
    
    CGImageRef cgImageRef = image.CGImage;
    
    ZBarSymbol* symbol = nil;
    
    for(symbol in [read scanImage:cgImageRef])
        break;
//    pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:symbol.data];
//    NSLog(@"symbol.data:%@",symbol.data);
    [self.delegate KBErweimaFinishWithString:symbol.data];

    [picker dismissViewControllerAnimated:YES completion:nil];
    NSLog(@"二维码棒棒的");
}


3二维码生成

#import "QRCodeGenerator.h"      //http://download.csdn.net/download/sjx19871225/5065683   下载地址


self.qrid = [[dic valueForKey:@"data"] valueForKey:@"token"];

            NSString * str = [NSString stringWithFormat:@"%@%@",DOWNLOADSERVER,self.qrid];

            self.qrImage.image = [QRCodeGenerator qrImageForString:str imageSize:200];



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值