使用 google 视觉 api 生成条形码或二维码
Generate barcode or qrcode using google vision api
我正在使用 google 视觉 API 扫描条形码和二维码。现在我想为用户提供更多便利,用户可以生成文本,url、phone、vcard 等 barcodes/qrcodes。
有人知道如何实现吗?因为 google Play 商店中有很多应用程序都在做同样的事情。
回答
你不能。
原因
不知道你用的是云端还是移动视觉api,两者都不支持条码生成。它们只能用于扫描条形码。
备选
您可以使用 ZXING 之类的东西来生成您的条形码。
我正在尝试使用此代码生成二维码,它对我有用
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;
}
试一试
我正在使用 google 视觉 API 扫描条形码和二维码。现在我想为用户提供更多便利,用户可以生成文本,url、phone、vcard 等 barcodes/qrcodes。
有人知道如何实现吗?因为 google Play 商店中有很多应用程序都在做同样的事情。
回答
你不能。
原因
不知道你用的是云端还是移动视觉api,两者都不支持条码生成。它们只能用于扫描条形码。
备选
您可以使用 ZXING 之类的东西来生成您的条形码。
我正在尝试使用此代码生成二维码,它对我有用
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;
}
试一试