The Mlkit barcode scanning library has an issue with scanning Code 39 barcodes. So I have to replace it with the zxing library that seems to have no issues.
However CameraX is giving me back an ImageProxy object, and the zxing MultiFormatReader accepts a BinaryBitmap object.
I'm having trouble converting from one to the other, and it's giving me an index out of bounds exception. Here's my code:
private fun createBinaryBitmap(imageProxy: ImageProxy): BinaryBitmap {
val data = ImageUtil.yuvImageToJpegByteArray(imageProxy, imageProxy.cropRect, 100)
val source = PlanarYUVLuminanceSource(
data,
imageProxy.width,
imageProxy.height,
0,
0,
imageProxy.width,
imageProxy.height,
false
)
return BinaryBitmap(HybridBinarizer(source))
}
I've looked at other places and questions, but I honestly can't find the right approach.
Here is what I found in the zxing doc. Arguments dataWidth and dataHeight are different of respectively imageProxy.width and imageProxy.height, since data is a cropped image of imageProxy.
public PlanarYUVLuminanceSource(byte[] yuvData,
int dataWidth,
int dataHeight,
int left,
int top,
int width,
int height,
boolean reverseHorizontal)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.