美文网首页
AVFoundation 从相册中读取二维码

AVFoundation 从相册中读取二维码

作者: Axiba | 来源:发表于2016-04-06 15:16 被阅读213次

1、例如在我们的导航栏中设置一个按钮

-(void)setupRightMenuButton{
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"相册中选" style:UIBarButtonItemStylePlain target:self action:@selector(takeQRCodeFromPic)];
}

2、初始化相册拾取器

-(void)takeQRCodeFromPic{

    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){
        UIImagePickerController *controller = [[UIImagePickerController alloc] init];
        controller.delegate = self;
        controller.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
        controller.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
        [self presentViewController:controller animated:YES completion:NULL];
        
    }else{
        
        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"设备不支持访问相册,请在设置->隐私->照片中进行设置!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
    
}

3、实现选中照片之后的代理事件,并将图片数据进行转码扫描

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    //1.获取选择的图片
    UIImage *image = info[UIImagePickerControllerOriginalImage];
    //2.初始化一个监测器
    CIDetector*detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:@{ CIDetectorAccuracy : CIDetectorAccuracyHigh }];
    
    [picker dismissViewControllerAnimated:YES completion:^{
        //监测到的结果数组
        NSArray *features = [detector featuresInImage:[CIImage imageWithCGImage:image.CGImage]];
        if (features.count >=1) {
            /**结果对象 */
            CIQRCodeFeature *feature = [features objectAtIndex:0];
            NSString *scannedResult = feature.messageString;
            RxWebViewController* webViewController = [[RxWebViewController alloc] initWithUrl:[NSURL URLWithString:scannedResult]];
            webViewController.navigationItem.hidesBackButton = YES;
            [self.navigationController pushViewController:webViewController animated:YES];
            
        }
        else{
            UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"该图片没有包含一个二维码!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alertView show];
            
        }
        
        
    }];
}

相关文章

  • AVFoundation 从相册中读取二维码

    1、例如在我们的导航栏中设置一个按钮 2、初始化相册拾取器 3、实现选中照片之后的代理事件,并将图片数据进行转码扫描

  • iOS AVFoundation 从相册中读取二维码

    1、例如在我们的导航栏中设置一个按钮 -(void)setupRightMenuButton{self.navig...

  • Metal-AVAssetReader

    AVAssetReader AVAssetReader是AVFoundation中的一个读取器对象 1、直接从存储...

  • iOS 相机权限 判断

    相机权限在#import 中 相机控制器调用 相册权限在...

  • 简单二维码的读取

    二维码的读取1.需要导入AVFoundation框架2.步骤:// 1). 初始化捕捉设备:AVCapture...

  • 二维码扫码采集与相册二维码提取 - iOS

    二维码扫码和相册二维码提取的方法在原生系统 AVFoundation 的 SDK 中提供了摄像头设备扫描捕获和检测...

  • 二维码读取

    来源读取主要用到CoreImage 不过要强调的是读取二维码的功能只有在iOS8之后才支持,我们需要在相册中调用一...

  • iOS 识别相册中图片的条形码

    用CIDetector类,但是这个类只能识别二维码图片,条形码目前暂不支持 SO:读取相册中的二维码/条形码,使用...

  • iOS从相册读取二维码

    分享的内容,大家看了后,不管有什么问题或者建议,都可以说出来,我都会一一做答,一起加油啦 原理和我的上一篇 << ...

  • 照片框架PhotoKit使用记录

    1、创建自定义相册并命名 2、保存图片至相册 3、从指定相册读取照片资源 4、删除指定相册的指定图片 5、将相册中...

网友评论

      本文标题:AVFoundation 从相册中读取二维码

      本文链接:https://www.haomeiwen.com/subject/mahmlttx.html