zoukankan      html  css  js  c++  java
  • 扫描相册中的二维码

    直接上代码:

    0.代理协议 

    UIImagePickerControllerDelegate, UINavigationControllerDelegate

    1.定义

    @property (strong, nonatomic) CIDetector *detector;

    2.“相册”按钮的点击事件

    -(void)clickRightBarButton:(UIBarButtonItem*)item
    
    {
    
        self.detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:@{ CIDetectorAccuracy : CIDetectorAccuracyHigh }];
    
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    
        picker.delegate = self;
    
        picker.allowsEditing = NO;
    
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    
        [self.navigationController presentViewController:picker animated:YES completion:nil];
    
    }
    

      

     

    3.照片选择后的代理方法

    - ( void )imagePickerController:( UIImagePickerController *)picker didFinishPickingMediaWithInfo:( NSDictionary *)info
    {
        [picker dismissViewControllerAnimated:YES completion:nil];
        UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
        if (!image){
            image = [info objectForKey:UIImagePickerControllerOriginalImage];
        }
        
        NSArray *features = [self.detector featuresInImage:[CIImage imageWithCGImage:image.CGImage]];
        if (features.count >=1) {
            CIQRCodeFeature *feature = [features objectAtIndex:0];
            NSString *scannedResult = feature.messageString;
            
            NSLog(@" ----  %@", scannedResult);
            NSArray *typeArray = [scannedResult componentsSeparatedByString:@","];
            if (typeArray.count <= 0) {
                return;
            }
           // 分析扫描结果      
            [self analyzeQRCode:typeArray];
        }
    }
    

      

     

     

  • 相关阅读:
    关于放入cookie中的中文取出后变乱码的问题及解决办法!
    用灌了google的颜色搜索,可以看看这个。
    趁准备换个工作的工夫,去天津走了一圈.
    python的面向对象学习分享
    Http Handler 介绍
    大型网站系统架构分析
    Http 请求处理流程
    uniapp nfc读写
    安卓的颜色透明度和html的不一样
    uniapp App上传文件
  • 原文地址:https://www.cnblogs.com/yangzhifan/p/4950053.html
Copyright © 2011-2022 走看看