Coder Social home page Coder Social logo

simon-leeeeeeeee / xcodescanner Goto Github PK

View Code? Open in Web Editor NEW
652.0 14.0 88.0 12.56 MB

A new frame for decode QR code and bar code on Android. It's faster, simpler and more accurate.

License: Apache License 2.0

Java 1.61% Makefile 3.54% C 61.14% Assembly 0.04% C++ 6.38% Shell 18.78% M4 3.89% Batchfile 0.32% Objective-C 2.04% Roff 1.80% HTML 0.29% sed 0.16%
android zbar qrcode-scanner barcode-scanner

xcodescanner's Issues

本来想用这个库的,但是引入都不成功。

Could not resolve all dependencies for configuration ':app:debugRuntimeClasspath'.
Could not determine artifacts for cn.simonlee.xcodescanner:zbar:1.1.8
Could not get resource 'https://jcenter.bintray.com/cn/simonlee/xcodescanner/zbar/1.1.8/zbar-1.1.8.aar'.
Could not HEAD 'https://jcenter.bintray.com/cn/simonlee/xcodescanner/zbar/1.1.8/zbar-1.1.8.aar'.
Connect to d29vzk4ow07wi7.cloudfront.net:443 [d29vzk4ow07wi7.cloudfront.net/54.230.118.75, d29vzk4ow07wi7.cloudfront.net/54.230.118.174, d29vzk4ow07wi7.cloudfront.net/54.230.118.24, d29vzk4ow07wi7.cloudfront.net/54.230.118.198] failed: Read timed out
Read timed out

魅族mx5运行报错

错误输出是
java.lang.RuntimeException: TextureReader Error! EGL MakeCurrent failure: EGL_BAD_MATCH
at com.simonlee.scanner.core.TextureReader.initEGL(TextureReader.java:242)
at com.simonlee.scanner.core.TextureReader.run(TextureReader.java:191)

混淆后报错

异常类型:java.lang.UnsatisfiedLinkError

异常信息:No implementation found for long cn.bertsir.zbar.Qr.Symbol.a() (tried Java_cn_bertsir_zbar_Qr_Symbol_a and Java_cn_bertsir_zbar_Qr_Symbol_a__)

关键方法:cn.bertsir.zbar.Qr.Symbol.a(Native Method)

混淆应该如何配置?

8.0.0系统 识别

今天用了下在华为8.0上识别,条形码识别很快,但是二维码识别不出来。

为什么会报下面的错误

E/libEGL: call to OpenGL ES API with no current context (logged once per thread)
cn.simonlee.demo.xcodescanner.ScanActivity.onSurfaceTextureDestroyed()

自己继承扫不出来

根据你的demo继承引入zbar也不行
自己直接加上依赖都不行,打开相机就在那里等着完全扫不出来

二维码无法识别,条码识别正常

机器是Android设备,但不是手机,下面是一些log

cn.simonlee.xcodescanner.core.NewCameraScanner.setPreviewSize() mPreviewSize = 1080x1848
cn.simonlee.xcodescanner.core.NewCameraScanner.takeOrientation() mOrientation = 0
cn.simonlee.xcodescanner.core.NewCameraScanner.getBigEnoughSize() minWidth = 1848 , minHeight = 1080
cn.simonlee.xcodescanner.core.NewCameraScanner.initSurfaceSize() mSurfaceSize = 1920x1080
cn.simonlee.xcodescanner.core.NewCameraScanner.initTextureReader() mTextureReader = 1920x1080
cn.simonlee.demo.xcodescanner.ScanActivity.openCameraSuccess() frameWidth = 1080 , frameHeight = 1920 , frameDegree = 0
cn.simonlee.xcodescanner.view.AdjustTextureView.setImageFrameMatrix() frameWH = 1080x1920 , frameDegree = 0
cn.simonlee.xcodescanner.view.AdjustTextureView.setImageFrameMatrix()B XY = 1 : 1.038961
cn.simonlee.xcodescanner.core.NewCameraScanner.setFrameRect() mOrientation = 0 frameRect = 0-0-1080-1848
cn.simonlee.xcodescanner.core.NewCameraScanner.setFrameRect() mClipRectRatio = RectF(0.0, 0.0, 0.9625, 1.0)

华为mate9无法识别问题

在华为mate9手机上 无法扫码识别 同一手机上的微信、自带浏览器以及第三方浏览器对同一二维码都可识别。图片无法上传 只能手打了
设备名称:HUAWEI Mate9
手机型号:MHA-AL00
版本号:MHA-AL00C00B233
EMUI版本:5.0.1
Android版本:7.0

RequestCode不能为负值,也不能大于16位bit值65536

MainActivity中:

 @Override
    public void onClick(View v) {
        int permissionState = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
        if (permissionState == PackageManager.PERMISSION_GRANTED) {
            startScan(v.getId());
        } else {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, v.getId());
        }
    }

不能用v.getId()作为requestCode,会直接崩溃。
不过你这个扫起来确实很快。这类项目github上有不少,但没见过一个好用的(因为很多改别人的),或多或少都有下面几个问题:
1、预览变形,这个也要看机型,但不知有没有可以兼容所有机型的方法。
2、扫码慢,复杂一点的就扫不出来
3、还是兼容性,在有些机型上会崩溃,但不可能测试到每个机型的,所以写这个需要经验吧,不知你这个兼容性如何,能否用于生产环境。

decodeForResult这个api的使用建议

我在使用void decodeForResult(Context context, Uri uri, int requestCode);这个api的时候发现不能识别相册中的二维码。
后来改用void decodeForResult(Bitmap bitmap, RectF rectClipRatio, int requestCode);也会有部分机器不能够识别,看了源码有一段话说对图片分辨率有要求小于等于1920 * 1080。于是乎,在onActivityResult相册返回的data通过getContentResolver().query获取图片路径并生成的bitmap一定要压缩才可以解析二维码。我最开始用data.getData()把获取到的uri传入最上面的那个decodeForResult在三星G9500手机上会报错的

一些建议

首先觉得作者这个做的还可以,至少体验上比其他的库快。自己也想做类似的库,但对相关的api不太熟,思路不清晰。不过建议是可以提的。
1、预览框和外面上下左右的阴影,是否有必要分开做。而且这个布局比较简单,完全用不到约束布局,不建议有了MaskRelativeLayout,还搞一个MaskConstraintLayout。没必要,约束布局还要引入一个库,这对一个本身就是库的来说,不太好。建议删除,也不需要花时间在这上面。
2、不管是zxing还是zbar,都是只负责解码和生成码的,不涉及UI以及camera预览,以及拾取的图像回调,所以做这类库,也主要就是封装这些东西,至于怎么处理解码,可以写个接口,然后就可以自己选(图像数据回调给接口了,至于怎么解析,选择zxing还是zbar,可以动态控制,zbar太大啦)。可以参考下面这个库的设计:https://github.com/themaster-gh/BGAQRCode-Android-master
3、接口设计有点复杂。用这个库的的话,需要实现3个接口CameraScanner.CameraListener, TextureView.SurfaceTextureListener, GraphicDecoder.DecodeListener,其实我觉得可以合并成一个接口就好,这些接口的很多方法在库的内部实现就可以(因为代码都是固定的,没必要每次都copy一遍)。
4、好像没有闪光灯控制的接口。不过按照计划,这个也会加的。

旋转扫描角度会扫描不出结果

我指的角度是扫描框和二维码边框的角度。二维码是个正方形,扫码框也是个正方形,一般扫描,扫码框的四边和二维码的四边都是大致平行的,但转一下角度(45°左右),就会扫不出结果。
测试机型:
一加三。
安卓8.0.

提几个需求,求别打

  1. 同时支持zxing和zar,默认走zar,如果zbr识别失败走zxing
  2. 扫描的时候如果发现距离过远,自动方法二维码图像,类似于微信和支付宝那样
  3. 增加二维码和条形码的生成

非常感谢楼主的开源,是我目前看到的扫码项目中,干货非常十足的项目

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.