Giter Club home page Giter Club logo

Comments (12)

LewinJun avatar LewinJun commented on July 18, 2024

安卓还是iOS?

from react-native-lewin-qrcode.

helloshuang avatar helloshuang commented on July 18, 2024

都有这个情况,ios一部分真机可以扫,模拟器不行,有的真机也不行,安卓我试了几个真机都不行

from react-native-lewin-qrcode.

LewinJun avatar LewinJun commented on July 18, 2024

麻烦你贴几个二维码给我,我试下,谢谢

from react-native-lewin-qrcode.

LewinJun avatar LewinJun commented on July 18, 2024

还有就是你用的哪些机型?

from react-native-lewin-qrcode.

helloshuang avatar helloshuang commented on July 18, 2024

6d345abe-1cf8-4618-a50f-c560a9209150
安卓的大多都不行,ios模拟器不行,真机可以

from react-native-lewin-qrcode.

noraliucode avatar noraliucode commented on July 18, 2024

請問目前安卓的掃描不支援嗎?

from react-native-lewin-qrcode.

LewinJun avatar LewinJun commented on July 18, 2024

微信群 加入群聊及时通知

from react-native-lewin-qrcode.

hi-zd avatar hi-zd commented on July 18, 2024

我也碰到类似问题,安卓有些图片无法识别

from react-native-lewin-qrcode.

LewinJun avatar LewinJun commented on July 18, 2024

最近抽时间 优化下, 最近项目太忙了,pc, mobile, app(安卓 iOS) ,小程序, 大前端要做的事太多了

from react-native-lewin-qrcode.

hi-zd avatar hi-zd commented on July 18, 2024

最近抽时间优化下,最近项目太忙了,pc,mobile,app(安卓iOS),小程序,大前端要做的事太多了

/**
* 扫描二维码图片的方法
*
* @param path
* @return
*/
` public Result scanningImage(String path) {
if (path == null || path.length() == 0) {
return null;
}
Map<DecodeHintType, Object> hints = new HashMap<>();
hints.put(DecodeHintType.CHARACTER_SET, "UTF8"); // 设置二维码内容的编码
hints.put(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);// 编码格式
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);// 花更多的时间用于寻找图上的编码,优化准确性,但不优化速度,Boolean类型
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; // 先获取原大小
Bitmap scanBitmap = BitmapFactory.decodeFile(path);
options.inJustDecodeBounds = false; // 获取新的大小
int sampleSize = (int) (options.outHeight / (float) 200);
// 添加以下代码
int w = options.outWidth;
int h = options.outHeight;
// 获取手机屏幕分辨率
DisplayMetrics dm = new DisplayMetrics();
getCurrentActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
int screenWidth = dm.widthPixels;
int screenHeight = dm.heightPixels;
// // 计算真实图片与屏幕分辨率的比率w
int widthSample = w / screenWidth;
int heightSample = h / screenHeight;
if (w > h && w > screenWidth) {// 如果宽度大的话根据宽度固定大小缩放
sampleSize = (int) (options.outWidth / screenWidth);
} else if (w < h && h > screenHeight) {// 如果高度高的话根据宽度固定大小缩放
sampleSize = (int) (options.outHeight / screenHeight);
}
if (sampleSize <= 0)
sampleSize = 1;

    options.inSampleSize = sampleSize;

    scanBitmap = BitmapFactory.decodeFile(path, options);
    int width = scanBitmap.getWidth();
    int height = scanBitmap.getHeight();
    int[] pixels = new int[width * height];
    scanBitmap.getPixels(pixels, 0, width, 0, 0, width, height);// 获取图片像素点
    RGBLuminanceSource source = new RGBLuminanceSource(scanBitmap.getWidth(), scanBitmap.getHeight(), pixels);
    BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
    QRCodeReader reader = new QRCodeReader();
    try {
        return reader.decode(bitmap1, hints);
    } catch (NotFoundException e) {
        e.printStackTrace();
    } catch (ChecksumException e) {
        e.printStackTrace();
    } catch (FormatException e) {
        e.printStackTrace();
    }
    return null;
}`

这是我对scanningImage的一些修改,在我的项目里能有一些优化,如果不需要兼容安卓7以下的话建议用compile 'com.google.zxing:core:3.4.0',效果还不错

from react-native-lewin-qrcode.

LewinJun avatar LewinJun commented on July 18, 2024

最近抽时间优化下,最近项目太忙了,pc,mobile,app(安卓iOS),小程序,大前端要做的事太多了

/**

  • 扫描二维码图片的方法
  • @param path
  • @return
    */
    ` public Result scanningImage(String path) {
    if (path == null || path.length() == 0) {
    return null;
    }
    Map<DecodeHintType, Object> hints = new HashMap<>();
    hints.put(DecodeHintType.CHARACTER_SET, "UTF8"); // 设置二维码内容的编码
    hints.put(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);// 编码格式
    hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);// 花更多的时间用于寻找图上的编码,优化准确性,但不优化速度,Boolean类型
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true; // 先获取原大小
    Bitmap scanBitmap = BitmapFactory.decodeFile(path);
    options.inJustDecodeBounds = false; // 获取新的大小
    int sampleSize = (int) (options.outHeight / (float) 200);
    // 添加以下代码
    int w = options.outWidth;
    int h = options.outHeight;
    // 获取手机屏幕分辨率
    DisplayMetrics dm = new DisplayMetrics();
    getCurrentActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
    int screenWidth = dm.widthPixels;
    int screenHeight = dm.heightPixels;
    // // 计算真实图片与屏幕分辨率的比率w
    int widthSample = w / screenWidth;
    int heightSample = h / screenHeight;
    if (w > h && w > screenWidth) {// 如果宽度大的话根据宽度固定大小缩放
    sampleSize = (int) (options.outWidth / screenWidth);
    } else if (w < h && h > screenHeight) {// 如果高度高的话根据宽度固定大小缩放
    sampleSize = (int) (options.outHeight / screenHeight);
    }
    if (sampleSize <= 0)
    sampleSize = 1;
    options.inSampleSize = sampleSize;

    scanBitmap = BitmapFactory.decodeFile(path, options);
    int width = scanBitmap.getWidth();
    int height = scanBitmap.getHeight();
    int[] pixels = new int[width * height];
    scanBitmap.getPixels(pixels, 0, width, 0, 0, width, height);// 获取图片像素点
    RGBLuminanceSource source = new RGBLuminanceSource(scanBitmap.getWidth(), scanBitmap.getHeight(), pixels);
    BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
    QRCodeReader reader = new QRCodeReader();
    try {
        return reader.decode(bitmap1, hints);
    } catch (NotFoundException e) {
        e.printStackTrace();
    } catch (ChecksumException e) {
        e.printStackTrace();
    } catch (FormatException e) {
        e.printStackTrace();
    }
    return null;
}`

这是我对scanningImage的一些修改,在我的项目里能有一些优化,如果不需要兼容安卓7以下的话建议用compile 'com.google.zxing:core:3.4.0',效果还不错

谢谢,最近我会上一个版本,结合zxing和zbar两者使用,如果其中一个没识别会尝试使用另外一种

from react-native-lewin-qrcode.

LewinJun avatar LewinJun commented on July 18, 2024

上面的最近抽空优化了,新版1.1可以识别上面的二维码了

from react-native-lewin-qrcode.

Related Issues (11)

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.