在ios 中 扫瞄二维码,条形码基本有 2中第三方的库,一个是zbar 一个是zxing,zxing 在android中表现的比较出色,但是在ios 中不是很好用,扫瞄效率低,我们一般都用zbar,但是有些 条形码就是很奇葩,用zbar无法识别,下面就是一种

我用了好多ios 的app 都无法识别, 《我查查》,《快拍二维码》,《微信》,自己用zbar都不行,最后用android 手机轻松扫瞄ok,哪我知道为什么了,是zxing可以搞定这种条形码。马上就换了zxing 来测试。 去github 找到了 zxing 的demo。但是悲剧的时无法识别各种条形码。

而且工程还报错。

报Private field 'cached_y_' not used 编译通不过,解决办法就是

删除工程“buliding setting”的"Other Warning Flags"  的后面的参数:
"-Werror" ,  "-Wno-unused-parameter"  等等

然后真机debug 完全ok,但是还是无法扫瞄 条形码!为什么呢?

我在网上着了下原因 ,问题解决了。

方法是:

1.修改 OverlayView.m文件中的61行左右

co

注释掉下面代码

// self.oneDMode = isOneDModeEnabled;  

2.在ZXingWidgetController.m中用这个函数替换以前的函数

也就是上面红色的部分做了修改

- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
       fromConnection:(AVCaptureConnection *)connection
{
  if (!decoding) {
    return;
  }
  CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
  /*Lock the image buffer*/
  CVPixelBufferLockBaseAddress(imageBuffer,0);
  /*Get information about the image*/
  size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
  size_t width = CVPixelBufferGetWidth(imageBuffer);
  size_t height = CVPixelBufferGetHeight(imageBuffer);   

  uint8_t* baseAddress = CVPixelBufferGetBaseAddress(imageBuffer);
  void* free_me = 0;
  if (true) { // iOS bug?
    uint8_t* tmp = baseAddress;
    int bytes = bytesPerRow*height;
    free_me = baseAddress = (uint8_t*)malloc(bytes);
    baseAddress[0] = 0xdb;
    memcpy(baseAddress,tmp,bytes);
  }  

  CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
  CGContextRef newContext =
    CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace,
                          kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst);   

  CGImageRef capture = CGBitmapContextCreateImage(newContext);
  CVPixelBufferUnlockBaseAddress(imageBuffer,0);
  free(free_me);  

  CGContextRelease(newContext);
  CGColorSpaceRelease(colorSpace);  

  CGRect cropRect = [overlayView cropRect];
  if (oneDMode) {
    // let's just give the decoder a vertical band right above the red line
<span style="color:#ff0000;">//    cropRect.origin.x = cropRect.origin.x + (cropRect.size.width / 2) - (ONE_D_BAND_HEIGHT + 1);
//    cropRect.size.width = ONE_D_BAND_HEIGHT;
//    // do a rotate
//    CGImageRef croppedImg = CGImageCreateWithImageInRect(capture, cropRect);
//    CGImageRelease(capture);
//    capture = [self CGImageRotated90:croppedImg];
//    capture = [self CGImageRotated180:capture];
//    //              UIImageWriteToSavedPhotosAlbum([UIImage imageWithCGImage:capture], nil, nil, nil);
//    CGImageRelease(croppedImg);
//    CGImageRetain(capture);
//    cropRect.origin.x = 0.0;
//    cropRect.origin.y = 0.0;</span>
    cropRect.size.width = CGImageGetWidth(capture);
    cropRect.size.height = CGImageGetHeight(capture);
  }  

  // N.B.
  // - Won't work if the overlay becomes uncentered ...
  // - iOS always takes videos in landscape
  // - images are always 4x3; device is not
  // - iOS uses virtual pixels for non-image stuff  

  {
    float height = CGImageGetHeight(capture);
    float width = CGImageGetWidth(capture);  

    CGRect screen = UIScreen.mainScreen.bounds;
    float tmp = screen.size.width;
    screen.size.width = screen.size.height;;
    screen.size.height = tmp;  

    cropRect.origin.x = (width-cropRect.size.width)/2;
    cropRect.origin.y = (height-cropRect.size.height)/2;
  }
  CGImageRef newImage = CGImageCreateWithImageInRect(capture, cropRect);
  CGImageRelease(capture);
<span style="color:#ff0000;"> // UIImage *scrn = [[UIImage alloc] initWithCGImage:newImage];
    int backCameraImageOrientation = UIImageOrientationRight;
    UIImage *scrn = [[UIImage alloc] initWithCGImage:newImage scale:
                     (CGFloat)1.0 orientation:backCameraImageOrientation];
</span>
  CGImageRelease(newImage);
  Decoder *d = [[Decoder alloc] init];
  d.readers = readers;
  d.delegate = self;
  cropRect.origin.x = 0.0;
  cropRect.origin.y = 0.0;
  decoding = [d decodeImage:scrn cropRect:cropRect] == YES ? NO : YES;
  [d release];
  [scrn release];
}   

3.在ViewController.mm 文件中做下面的修改

#import "MultiFormatOneDReader.h"  

- (void)pressButton1:(UIButton *)button
{
  <span style="color:#ff0000;">  ZXingWidgetController *widController = [[ZXingWidgetController alloc] initWithDelegate:self showCancel:YES OneDMode:YES];
    NSMutableSet *readers = [[NSMutableSet alloc] init];
    QRCodeReader *qrcodeReader = [[QRCodeReader alloc] init];  

    MultiFormatOneDReader *OneReaders=[[MultiFormatOneDReader alloc]init];  

    [readers addObject:qrcodeReader];
     [readers addObject:OneReaders];</span>
    widController.readers = readers;
    [self presentViewController:widController animated:YES completion:^{}];
}  

c然后修改全部ok了,扫瞄条形码就完全ok了。

看效果:

二:


三:

四:

ios zxing扫码问题的更多相关文章

  1. zxing 扫码第三方SDK版本不兼容问题

    在AndroidStudio环境下,或许会遇到下面的问题: Error:Execution failed for task ':app:preDebugAndroidTestBuild'. > ...

  2. Blazor组件自做三 : 使用JS隔离封装ZXing扫码

    Blazor组件自做三 : 使用JS隔离封装ZXing扫码 本文基础步骤参考前两篇文章 Blazor组件自做一 : 使用JS隔离封装viewerjs库 Blazor组件自做二 : 使用JS隔离制作手写 ...

  3. zxing扫码--镭射线

    同步发表于http://avenwu.net/2015/09/15/zxing_view_finder_laser 在很多应用中都有二维码扫描的需求,比如微信,通过扫描电脑二维码,实现用户登录授权: ...

  4. iOS ZBar扫码简单实现

    导入ZBarSDK文件并引入一下框架 AVFoundation.framework CoreMedia.framework CoreVideo.framework QuartzCore.framewo ...

  5. ionic3 实现扫码功能

    ionic3 通过插件phonegap-plugin-barcodescanner,调用机器硬件摄像头实现扫码功能. 首先当然先了解下 phonegap-plugin-barcodescanner,这 ...

  6. ZXing Blazor 扫码组件 , ssr/wasm通用

    项目介绍 本项目是利用 ZXing 进行封装的 Blazor 组件库 直接调用手机或者桌面电脑摄像头进行扫码 项目截图              项目地址 https://github.com/den ...

  7. 安卓扫码:简单的ZXing使用记录

    ZXing是Google提供的条形码.二维码等的生成.解析的库.最近工作需求去研究了一下,主要是研究怎么扫描二维码(QRCode).网上教程也不少,但大多看了不明所以,甚至看了半天都不知道解码到底从哪 ...

  8. C#-Xamarin利用ZXing.Net.Mobile进行扫码

    前言 很多人觉得Xamarin的开源少,没法用来开发项目. 但,实际上Xamarin已经有很多开源代码了:只要不是特别特殊的项目,基本上是都可以满足开发. 下面我们来看一下Xamarin中利用开源代码 ...

  9. iOS Swift WisdomScanKit二维码扫码SDK,自定义全屏拍照SDK,系统相册图片浏览,编辑SDK

    iOS Swift WisdomScanKit 是一款强大的集二维码扫码,自定义全屏拍照,系统相册图片编辑多选和系统相册图片浏览功能于一身的 Framework SDK [1]前言:    今天给大家 ...

随机推荐

  1. bzoj4830 hnoi2017 抛硬币

    题目描述 小 A 和小 B 是一对好朋友,他们经常一起愉快的玩耍.最近小 B 沉迷于**师手游,天天刷本,根本无心搞学习.但是已经入坑了几个月,却一次都没有抽到 SSR,让他非常怀疑人生.勤勉的小 A ...

  2. BZOJ3065(替罪羊树套线段树)

    以前看到这题都瑟瑟发抖,终于过了心情舒畅. 按下标为关键字建替罪羊树,每个结点开一个权值线段树,维护的这个结点代表的子树的信息. 这题还得垃圾回收,自己yy的,不知对不对.. #include < ...

  3. wpf中静态资源和动态资源的区别

    静态资源(StaticResource)指的是在程序载入内存时对资源的一次性使用,之后就不再访问这个资源了. 动态资源(DynamicResource)指的是在程序运行过程中然会去访问资源.

  4. C语言中#define的用法

    今天整理了一些#define的用法,与大家共享! 1.简单的define定义 #define MAXTIME 1000 一个简单的MAXTIME就定义好了,它代表1000,如果在程序里面写 if(i& ...

  5. Awesome-Text-Classification:文本分类资源合集

    Awesome-Text-Classification https://github.com/fendouai/Awesome-Text-Classification Projects fastTex ...

  6. 将 Hexo 个人博客同时部署到 GitHub 和 Coding 上

    一.将个人博客托管到 GitHub 上 关于如何快速搭建自己的个人博客,如何完善自己的个人博客,什么是 GitHub ,如何将自己的博客代码托管到 GitHub 上面等等问题,我之前写过三篇文章已经做 ...

  7. CRM客户关系管理系统(一)

    第一章.CRM介绍和开发流程 1.1.CRM简介 客户关系管理(CRM) 客户关系管理(customer relationship management)的定义是:企业为提高核心竞争力,利用相应的信息 ...

  8. Servlet生命周期与工作原理(转载)

    Servlet生命周期分为三个阶段: 1,初始化阶段  调用init()方法 2,响应客户请求阶段 调用service()方法 3,终止阶段 调用destroy()方法 Servlet初始化阶段: 在 ...

  9. 全局变量&局部变量,global&nonlocal

    ###全局变量与局部变量 1.函数内部的变量名如果第一次出现,且出现在=前面,即被视为定义一个局部变量,不管全局域中有没有用到该变量名,函数中使用的将是局部变量 2.函数内部的变量名如果第一次出现,且 ...

  10. C#系统之垃圾回收

    1. using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syste ...