Android 使用google vision api生成条形码或qrcode

Android 使用google vision api生成条形码或qrcode,android,google-play-services,google-vision,Android,Google Play Services,Google Vision,我正在使用谷歌视觉API扫描条形码和qrcodes。现在,我想为用户提供一个功能,用户可以生成文本、url、电话、vcard等条形码/qrcodes 有人知道如何做到这一点吗?因为google play store上有很多应用程序都在做同样的事情。Answer 你不能 理由 我不知道您是在使用cloud还是mobile vision api,但两者都不支持条形码生成。它们只能用于扫描条形码 可供替代的 您可以使用类似的方法生成条形码。我正在尝试使用此代码生成二维码。使用此代码对我有效 p

我正在使用谷歌视觉API扫描条形码和qrcodes。现在,我想为用户提供一个功能,用户可以生成文本、url、电话、vcard等条形码/qrcodes

有人知道如何做到这一点吗?因为google play store上有很多应用程序都在做同样的事情。

Answer 你不能

理由 我不知道您是在使用cloud还是mobile vision api,但两者都不支持条形码生成。它们只能用于扫描条形码

可供替代的
您可以使用类似的方法生成条形码。

我正在尝试使用此代码生成二维码。使用此代码对我有效

    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;
}
公共静态位图生成qrcode(字符串mycdetext)引发WriterException{
Hashtable hintMap=新的Hashtable();
hintMap.put(EncodeHintType.ERROR\u CORRECTION,ErrorCorrectionLevel.H);/H=30%伤害
QRCodeWriter QRCodeWriter=新的QRCodeWriter();
int size=256;
BitMatrix BitMatrix=qrCodeWriter.encode(myCodeText,BarcodeFormat.QR_代码,大小,大小,hintMap);
int-width=bitMatrix.getWidth();
位图bmp=Bitmap.createBitmap(宽度、宽度、Bitmap.Config.RGB_565);
对于(int x=0;x

试试看

如果您想生成条形码,可以使用zxing库。