Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. // implementation 'com.google.zxing:core:3.3.2'
  2. public static String parseQRStream(InputStream stream) {
  3. // DecodeHintType 和EncodeHintType
  4. Hashtable<DecodeHintType, String> hints = new Hashtable<>();
  5. // 设置二维码内容的编码
  6. hints.put(DecodeHintType.CHARACTER_SET, "utf-8");
  7.  
  8. Bitmap bitmap = BitmapFactory.decodeStream(stream);
  9. if (bitmap == null) {
  10. return null;
  11. }
  12. int width = bitmap.getWidth();
  13. int height = bitmap.getHeight();
  14. int[] pixels = new int[width * height];
  15. bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
  16. RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
  17. Result result = null;
  18. try {
  19. result = new MultiFormatReader().decode(new BinaryBitmap(new HybridBinarizer(source)), hints);
  20. return result.getText();
  21. } catch (NotFoundException e) {
  22. e.printStackTrace();
  23. }
  24. return null;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement