Search code examples
androidbitmapqr-codezxing

detect pictures whether qr-code or not


I'v been using zxing core recently, but I'v no idea how to detect a bitmap or other picture types whether a QR code or not. Any help can fix this? Using zxing is better while other libraries is OK.Thanks.


Solution

  • First You have to learn what is a QR code it is a two-dimensional barcode.you convert normal text to QR code and read a QR code to convert to string.

    in zxing you can make a qr code from this code

    public static Bitmap encodeToQrCode(String text, int width, int height){
        QRCodeWriter writer = new QRCodeWriter();
        BitMatrix matrix = null;
        try {
            matrix = writer.encode(text, BarcodeFormat.QR_CODE, 100, 100);
        } catch (WriterException ex) {
            ex.printStackTrace();
        }
        Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
        for (int x = 0; x < width; x++){
            for (int y = 0; y < height; y++){
                bmp.setPixel(x, y, matrix.get(x,y) ? Color.BLACK : Color.WHITE);
            }
        }
        return bmp;
    }
    

    the above code produce a bitmap image you can display it to an imageview.and remember this qr code readers decode QR codes to string.it dosn't work if the QR code not properly encoded