Android setBarcodeFormats(条形码.QR_码)不起作用
我正在使用Google Play Vision API检测二维码。我对其他格式不感兴趣,所以我尝试使用该API调用来加快检测速度。如果我将其称为Android setBarcodeFormats(条形码.QR_码)不起作用,android,qr-code,google-vision,Android,Qr Code,Google Vision,我正在使用Google Play Vision API检测二维码。我对其他格式不感兴趣,所以我尝试使用该API调用来加快检测速度。如果我将其称为setBarcodeFormats(Barcode.ALL\u FORMATS),它可以检测到格式为256(qr\u code)的二维码,但是如果我将其初始化为setBarcodeFormats(Barcode.qr\u code),它不会检测到任何东西。以下是一些代码片段: override fun onCreate(savedInstanceStat
setBarcodeFormats(Barcode.ALL\u FORMATS)
,它可以检测到格式为256(qr\u code)的二维码,但是如果我将其初始化为setBarcodeFormats(Barcode.qr\u code)
,它不会检测到任何东西。以下是一些代码片段:
override fun onCreate(savedInstanceState: Bundle?) {
...
barcodeDetector = BarcodeDetector.Builder(applicationContext).setBarcodeFormats(Barcode.ALL_FORMATS).build()
...
private inner class ImageReaderOnImageAvailableListenerImpl : ImageReader.OnImageAvailableListener {
override fun onImageAvailable(reader: ImageReader) {
val image = reader.acquireNextImage()
val buffer = image.planes[0].buffer;
val bitmap: Bitmap? = if (buffer.hasArray()) {
BitmapFactory.decodeByteArray(buffer.array(), buffer.arrayOffset(), buffer.remaining(), null);
} else {
val byteArray = ByteArray(buffer.remaining())
buffer.get(byteArray)
BitmapFactory.decodeByteArray(byteArray, 0, byteArray.size, null);
}
val barcodes = barcodeDetector.detect(Frame.Builder().setBitmap(bitmap).build())
image.close()
this@QrCodeCaptureActivity.imageView.setImageBitmap(bitmap)
if (barcodes.size() > 0) {
for (index in 0 until barcodes.size()) {
val barcode = barcodes.valueAt(index)
logd("barcode $index: ${barcode.format} ${barcode.valueFormat} ${barcode.rawValue}")
}
} else {
logd("no barcodes (${image.width}x${image.height})")
}
}
}
我也注意到了这一点,我认为这是一个错误。我刚和allI去了我也注意到了这一点,我想这是一个错误。最后我和所有人都去了