ZXing convert Bitmap to BinaryBitmap

后端 未结 3 1068
难免孤独
难免孤独 2020-12-04 20:19

I am using OpenCV and Zxing, and I\'d like to add 2d code scanning. I have a few types of images that I could send. Probably the best is Bitmat (the other option is OpenCV

3条回答
  •  渐次进展
    2020-12-04 21:06

    public static String readQRImage(Bitmap bMap) {
        String contents = null;
    
        int[] intArray = new int[bMap.getWidth()*bMap.getHeight()];  
        //copy pixel data from the Bitmap into the 'intArray' array  
        bMap.getPixels(intArray, 0, bMap.getWidth(), 0, 0, bMap.getWidth(), bMap.getHeight());  
    
        LuminanceSource source = new RGBLuminanceSource(bMap.getWidth(), bMap.getHeight(), intArray);
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    
        Reader reader = new MultiFormatReader();// use this otherwise ChecksumException
        try {
            Result result = reader.decode(bitmap);
            contents = result.getText(); 
            //byte[] rawBytes = result.getRawBytes(); 
            //BarcodeFormat format = result.getBarcodeFormat(); 
            //ResultPoint[] points = result.getResultPoints();
        } catch (NotFoundException e) { e.printStackTrace(); } 
        catch (ChecksumException e) { e.printStackTrace(); }
        catch (FormatException e) { e.printStackTrace(); } 
        return contents;
    }
    

提交回复
热议问题