Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // implementation 'com.google.zxing:core:3.3.2'
- public static String parseQRStream(InputStream stream) {
- // DecodeHintType 和EncodeHintType
- Hashtable<DecodeHintType, String> hints = new Hashtable<>();
- // 设置二维码内容的编码
- hints.put(DecodeHintType.CHARACTER_SET, "utf-8");
- Bitmap bitmap = BitmapFactory.decodeStream(stream);
- if (bitmap == null) {
- return null;
- }
- int width = bitmap.getWidth();
- int height = bitmap.getHeight();
- int[] pixels = new int[width * height];
- bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
- RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
- Result result = null;
- try {
- result = new MultiFormatReader().decode(new BinaryBitmap(new HybridBinarizer(source)), hints);
- return result.getText();
- } catch (NotFoundException e) {
- e.printStackTrace();
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement