ios zxing扫码问题
在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行左右
注释掉下面代码
// 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扫码问题的更多相关文章
- zxing 扫码第三方SDK版本不兼容问题
在AndroidStudio环境下,或许会遇到下面的问题: Error:Execution failed for task ':app:preDebugAndroidTestBuild'. > ...
- Blazor组件自做三 : 使用JS隔离封装ZXing扫码
Blazor组件自做三 : 使用JS隔离封装ZXing扫码 本文基础步骤参考前两篇文章 Blazor组件自做一 : 使用JS隔离封装viewerjs库 Blazor组件自做二 : 使用JS隔离制作手写 ...
- zxing扫码--镭射线
同步发表于http://avenwu.net/2015/09/15/zxing_view_finder_laser 在很多应用中都有二维码扫描的需求,比如微信,通过扫描电脑二维码,实现用户登录授权: ...
- iOS ZBar扫码简单实现
导入ZBarSDK文件并引入一下框架 AVFoundation.framework CoreMedia.framework CoreVideo.framework QuartzCore.framewo ...
- ionic3 实现扫码功能
ionic3 通过插件phonegap-plugin-barcodescanner,调用机器硬件摄像头实现扫码功能. 首先当然先了解下 phonegap-plugin-barcodescanner,这 ...
- ZXing Blazor 扫码组件 , ssr/wasm通用
项目介绍 本项目是利用 ZXing 进行封装的 Blazor 组件库 直接调用手机或者桌面电脑摄像头进行扫码 项目截图 项目地址 https://github.com/den ...
- 安卓扫码:简单的ZXing使用记录
ZXing是Google提供的条形码.二维码等的生成.解析的库.最近工作需求去研究了一下,主要是研究怎么扫描二维码(QRCode).网上教程也不少,但大多看了不明所以,甚至看了半天都不知道解码到底从哪 ...
- C#-Xamarin利用ZXing.Net.Mobile进行扫码
前言 很多人觉得Xamarin的开源少,没法用来开发项目. 但,实际上Xamarin已经有很多开源代码了:只要不是特别特殊的项目,基本上是都可以满足开发. 下面我们来看一下Xamarin中利用开源代码 ...
- iOS Swift WisdomScanKit二维码扫码SDK,自定义全屏拍照SDK,系统相册图片浏览,编辑SDK
iOS Swift WisdomScanKit 是一款强大的集二维码扫码,自定义全屏拍照,系统相册图片编辑多选和系统相册图片浏览功能于一身的 Framework SDK [1]前言: 今天给大家 ...
随机推荐
- Windows 2008 R2_NLB网络负载均衡(图文详解)(转)
目录 前言 软件环境 DNS域名服务器 DNS服务器原理 DNS域名空间 DNS区域 DNS服务器的类别 DNS查询模式 缓存文件 配置DNS服务器 DNS服务的应用 新建子域 在DNS正向解析中新建 ...
- ionic3-ng4学习见闻--(自定义ion-tab图标)
学习混合开发语言,目的就是为了快速开发一个适用于多平台的app. app基本都会有footer,也就是tabbar,用来快速导航不同的页面. ionic也有这个组件,ion-tab. 常用方法如下: ...
- 浅谈Trie树(字典树)
Trie树(字典树) 一.引入 字典是干啥的?查找字的. 字典树自然也是起查找作用的.查找的是啥?单词. 看以下几个题: 1.给出n个单词和m个询问,每次询问一个单词,回答这个单词是否在单 ...
- ThreadLocal基本原理及运用
ThreadLocal提供本地线程变量.这个变量里面的值(通过get方法获取)是和其他线程分割开来的,变量的值只有当前线程能访问到,不像一般的类型比如Person,Student类型的变量,只要访问到 ...
- Angular5学习笔记 http请求
在anular4更新到angular5后,有些模块也发生了有些变化,例如http模块. 首先在app.module.ts里面引入HttpClientModule import { HttpClient ...
- Django笔记--视图
URLconf 在settings.py文件中通过ROOT_URLCONF指定根级url的配置 urlpatterns是一个url()实例的列表 一个url()对象包括: 正则表达式 视图函数 名称n ...
- day07 Cookie 和 Session(非常重要)
day07 Cookie 和 Session 1. 会话技术 2. cookie 的方法和 cookie 案例-显示用户上次访问网站的时间 3. cookie 的细节 - 删除 cookie 4. S ...
- 566. Reshape the Matrix
In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new o ...
- 南京邮电大学java程序设计作业在线编程第五次作业
王利国的"Java语言程序设计第5次作业(2018)"详细 主页 我的作业列表 作业结果详细 总分:100 选择题得分:50 1. 以下哪一个工具是Java的编译器?( ) A. ...
- Node.js JXcore 打包
Node.js 是一个开放源代码.跨平台的.用于服务器端和网络应用的运行环境. JXcore 是一个支持多线程的 Node.js 发行版本,基本不需要对你现有的代码做任何改动就可以直接线程安全地以多线 ...