使用Google Vision API生成条形码或二维码

4
我正在使用谷歌视觉 API 扫描条形码和二维码。现在我想为用户提供更多功能,使用户能够生成文本、网址、电话、vCard 等条形码/二维码。
那么,有人知道如何实现吗?因为谷歌 play 商店上有很多应用程序都可以做同样的事情。

如果您想生成条形码,可以使用zxing库。https://github.com/zxing/zxing - baldguy
2个回答

7

答案

不行。

原因

我不知道你是使用云端还是移动端视觉API,但是两者都不支持条形码生成。它们只能用于扫描条形码。

替代方案

您可以使用类似ZXING的工具来生成您的条形码。


0

我正在尝试使用这段代码生成二维码,它对我有效:

    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;
}

试一下


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接