长按图片识别图中二维码:

 // 长按图片识别二维码 

     UILongPressGestureRecognizer *QrCodeTap = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(QrCodeClick:)];

     [self.view addGestureRecognizer:QrCodeTap];

 - (void)QrCodeClick:(UILongPressGestureRecognizer *)pressSender {

     if (pressSender.state != UIGestureRecognizerStateBegan) {

         return;//长按手势只会响应一次

     }

 //    MJPhoto *photo = _photos[_currentPhotoIndex];

     //截图 再读取

     //第一个参数表示区域大小。第二个参数表示是否是非透明的。如果需要显示半透明效果,需要传NO,否则传YES。第三个参数就是屏幕密度了,获取当前屏幕分辨率[UIScreen mainScreen].scale

     UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, YES, 2.2);

     CGContextRef context = UIGraphicsGetCurrentContext();

     [self.view.layer renderInContext:context];

     UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

     UIGraphicsEndImageContext();

     CIImage *ciImage = [[CIImage alloc] initWithCGImage:image.CGImage options:nil];

     CIContext *ciContext = [CIContext contextWithOptions:@{kCIContextUseSoftwareRenderer : @(YES)}]; // 软件渲染

     CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:ciContext options:@{CIDetectorAccuracy : CIDetectorAccuracyHigh}];// 二维码识别

     NSArray *features = [detector featuresInImage:ciImage];

     if (features.count) {

         for (CIQRCodeFeature *feature in features) {

             NSLog(@"qrCodeUrl = %@",feature.messageString); // 打印二维码中的信息

             qrCodeUrl = feature.messageString;

         }

         // 初始化弹框 第一个参数是设置距离底部的边距

         alertview = [[RomAlertView alloc] initWithMainAlertViewBottomInset: Title:nil detailText:nil cancelTitle:nil otherTitles:[NSMutableArray arrayWithObjects:@"保存图片",@"识别图中二维码",nil]];

         alertview.tag = ;

         // 设置弹框的样式

         alertview.RomMode = RomAlertViewModeBottomTableView;

         // 设置弹框从什么位置进入 当然也可以设置什么位置退出

         [alertview setEnterMode:RomAlertEnterModeBottom];

         // 设置代理

         [alertview setDelegate:self];

         // 显示 必须调用 和系统一样

         [alertview show];

     } else {

         NSLog(@"图片中没有二维码");

     }

 }

 #pragma mark -- RomAlertViewDelegate 弹框识别图中二维码

 - (void)alertview:(RomAlertView *)alertview didSelectRowAtIndexPath:(NSIndexPath *)indexPath

 {

     if (alertview.tag == ) {

         if ([alertview.otherTitles[indexPath.row]  isEqualToString:@"保存图片"]) {

             NSLog(@"保存图片");

             [self saveButtonPressed];

         }else if ([alertview.otherTitles[indexPath.row] isEqualToString:@"识别图中二维码"]){

             NSLog(@"识别图中二维码");

             // 隐藏

             [alertview hide];

             [self leftBackButtonPressed];

             AppDelegate *delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];

             if([delegate.window.rootViewController isKindOfClass:[UITabBarController class]]){

                 UITabBarController *tabBarController = (UITabBarController *)delegate.window.rootViewController;

                 UINavigationController *navigationController = [tabBarController selectedViewController];

                 UIViewController *vc = navigationController.topViewController;

                 //对结果进行处理跳转网页

                 ADWebViewViewController *controller = [[ADWebViewViewController alloc] init];

                 controller.m_url = qrCodeUrl;

                 controller.hidesBottomBarWhenPushed = YES;

                 [vc.navigationController pushViewController:controller animated:YES];

             }

         }

     }

 }

iOS - 长按图片识别图中二维码的更多相关文章

  1. Vue实现长按图片识别图中二维码

    Vue实现长按图片识别图中二维码 思路:要想实现可以识别图片中的二维码,那必定是要将这张图进行上传操作,上传则需要file对象格式.不管是在H5还是APP中,展示的图片都是通过url的方式展示在img ...

  2. C#识别图中二维码

    1.在NuGet中添加 ZXing.Net 2.实例代码 /// <summary> /// 识别图中二维码 /// </summary> /// <param name ...

  3. android选取系统相册图片后,识别图中二维码

    项目中添加设备操作需要扫描二维码,考虑到多种扫码方式,也添加直接识别二维码图片的操作. 首先跳转系统相册选取图片 Intent intent = new Intent(Intent.ACTION_PI ...

  4. Android 长按识别图中二维码 zxing

    #基于 Zxing, 初学Android 代码质量不高 //长按,通过zxing读取图片,判断是否有二维码 bigImage.setOnLongClickListener(new View.OnLon ...

  5. 【转】Delphi+Halcon实战一:两行代码识别QR二维码

    Delphi+Halcon实战一:两行代码识别QR二维码 感谢网友:绝代双椒( QQ号应原作者要求隐藏了:xxxx6348)的支持 本文是绝代双椒的作品,因为最近在忙zw量化培训,和ziwang.co ...

  6. zxing 如何识别反转二维码

    说起二维码扫描,估计很多人用的是 zxing 吧. 然而 zxing 虽然好用,但是却有一些坑. 这边分析一下自己实际项目遇到的一个坑. 什么坑呢? 下面举个栗子你就懂了. 这边生成二维码使用的是网络 ...

  7. 二维码合成,将苹果和安卓(ios和android)合成一个二维码,让用户扫描一个二维码就可以分别下载苹果和安卓的应用

    因为公司推广的原因,没有合适的将苹果和安卓(ios和android)合成一个二维码的工具. 因为这个不难,主要是根据浏览器的UA进行判断,所以就自己开发了一个网站 网站名称叫:好推二维码  https ...

  8. php 合并图片 (将活动背景图片和动态二维码图片合成一张图片)

    <?php //案例一:将活动背景图片和动态二维码图片合成一张图片 //图片一 $path_1 = './background.png'; //图片二 $path_2 = './FU0851_2 ...

  9. iOS中二维码的生成与使用(入门篇)

    这里简单总结一下关于二维码的扫描与生成,用的是原生的AVFoundation框架,其实这个框架目前功能还是够用的,不过这里推荐一个二维码扫描的第三方(face++),网址就不贴了,直接度娘就OK,里面 ...

随机推荐

  1. MongoDB数据直接转移

    本方法较为暴力,有待验证,重要资料切勿使用.... 1.把一台电脑上MongoDB的--dbpath 下的文件夹  直接复制过来,放在新设备上 2.写个可爱的批处理文件 其实,就是改了个--dbpat ...

  2. Oracle:oratop 第一栏中的 {n}er 的含义,及如何清除这个er

    在oratop监控中: 第一栏的er[不]为{0}!说明Oracle的ADR诊断体系内发现有错误事件(problem + incident) 该信息实际是从一张视图内得来的: select * fro ...

  3. [转] 关于QT的系统总结

    出处:http://www.cnblogs.com/wangqiguo/p/4625611.html 阅读目录 编译环境与开发流程 QT项目的构成及原理 QT中的布局 QT中的通用控件 QVarian ...

  4. Linux下php安装Redis安装

    1. 下载  redis-2.4.14.tar.gz 2. 解压 tar -zxvf redis-2.4.14.tar.gz 3.cd redis-2.4.14 4. make 注意:出错 1. CC ...

  5. 表单验证&lt;AngularJs&gt;

    经常使用的表单验证指令 1. 必填项验证 某个表单输入是否已填写,仅仅要在输入字段元素上加入HTML5标记required就可以: <input type="text" re ...

  6. hdu5289 2015多校联合第一场1002 Assignment

    题意:给出一个数列.问当中存在多少连续子区间,当中子区间的(最大值-最小值)<k 思路:设dp[i]为从区间1到i满足题意条件的解.终于解即为dp[n]. 此外 如果对于arr[i] 往左遍历 ...

  7. HDOJ 4276 The Ghost Blows Light(树形DP)

    Problem Description My name is Hu Bayi, robing an ancient tomb in Tibet. The tomb consists of N room ...

  8. C#调用外部DLL介绍及使用详解

    一.      DLL与应用程序 动态链接库(也称为DLL,即为“Dynamic Link Library”的缩写)是Microsoft Windows最重要的组成要素之一,打开Windows系统文件 ...

  9. ios开发之--仿购物类详情页面数量添加小功能

    话不多说先上图:

  10. SpringBoot application.properties (application.yml)优先级从高到低

    SpringBoot application.properties(application.yml) 优先级从高到低 SpringBoot配置文件优先级从高到低 =================== ...