Generate barcode or qrcode using google vision api

5.9k views Asked by At

I am using google vision API to scan the barcodes and qrcodes. Now I want to give one more facility to the users that user can generate text, url, phone, vcard etc barcodes/qrcodes.

So anybody knows how to achieve this? Because there are lots of app on google play store those are doing the same things.

2

There are 2 answers

0
Steve2955 On BEST ANSWER

Answer

You can't.

Reason

I don't know if you are using the cloud or the mobile vision api, but both do not support barcode generation. They can only be used to scan barcodes.

Alternative

You could use something like ZXING to generate your barcodes.

0
yousef On

i'm try this code to generate Qr it works for me using this code

    public static Bitmap generateQrCode(String myCodeText) throws WriterException {
    Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<EncodeHintType, ErrorCorrectionLevel>();
    hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); // H = 30% damage
    QRCodeWriter qrCodeWriter = new QRCodeWriter();
    int size = 256;
    BitMatrix bitMatrix= qrCodeWriter.encode(myCodeText,BarcodeFormat.QR_CODE, size, size, hintMap);
    int width = bitMatrix.getWidth();
    Bitmap bmp = Bitmap.createBitmap(width, width, Bitmap.Config.RGB_565);
    for (int x = 0; x < width; x++) {
        for (int y = 0; y < width; y++) {
            bmp.setPixel(y, x, bitMatrix.get(x, y) ? Color.BLACK : Color.WHITE);
        }
    }
    return bmp;
}

try it