Comments (12)
安卓还是iOS?
from react-native-lewin-qrcode.
都有这个情况,ios一部分真机可以扫,模拟器不行,有的真机也不行,安卓我试了几个真机都不行
from react-native-lewin-qrcode.
麻烦你贴几个二维码给我,我试下,谢谢
from react-native-lewin-qrcode.
还有就是你用的哪些机型?
from react-native-lewin-qrcode.
from react-native-lewin-qrcode.
請問目前安卓的掃描不支援嗎?
from react-native-lewin-qrcode.
微信群 加入群聊及时通知
from react-native-lewin-qrcode.
我也碰到类似问题,安卓有些图片无法识别
from react-native-lewin-qrcode.
最近抽时间 优化下, 最近项目太忙了,pc, mobile, app(安卓 iOS) ,小程序, 大前端要做的事太多了
from react-native-lewin-qrcode.
最近抽时间优化下,最近项目太忙了,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.
最近抽时间优化下,最近项目太忙了,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.
上面的最近抽空优化了,新版1.1可以识别上面的二维码了
from react-native-lewin-qrcode.
Related Issues (11)
- cannot read property 'readerQR' of undefined HOT 2
- null is not object (evaluating 'QRScanReader.readerQr) HOT 3
- pod install的时候报错[!] No podspec found for `QrCode` in `../node_modules/react-native-lewin-qrcode`
- Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
- ios 无法识别 HOT 1
- cannot read property 'readerQR' of undefined
- 打包报错'linker command failed with exit code 1' HOT 2
- 本地编译正常 打包报错 ld: library not found for -lQRCode HOT 2
- android 上使用带logo 的二维码解析出错 HOT 3
- 安卓扫码会报错 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-lewin-qrcode.