In Android Studio Emulator (Pixel 4, API30), zxing 3.5.0 recognizes qr code in portrait orientation, but not in landscape orientation. On my hardware it behaves just the opposite: landscape works OK, but not portrait. What can I do?
landscape (not recognizing qr)
public abstract class QRCodeAnalyzer implements ImageAnalysis.Analyzer{
@Override
public void analyze(@NonNull ImageProxy image) {
if (image.getFormat() == YUV_420_888 || image.getFormat() == YUV_422_888 || image.getFormat() == YUV_444_888) {
ByteBuffer byteBuffer = image.getPlanes()[0].getBuffer();
byte[] imageData = new byte[byteBuffer.capacity()];
byteBuffer.get(imageData);
Log.d("QR", "" + image.getImageInfo().getRotationDegrees());
PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(
imageData,
image.getWidth(), image.getHeight(),
0, 0,
image.getWidth(), image.getHeight(),
false
);
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
Map<DecodeHintType, Object> hints = new HashMap<>();
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
try {
Result result = new QRCodeMultiReader().decode(binaryBitmap, hints);
onQRCodeFound(result);
} catch (FormatException | ChecksumException | NotFoundException e) {
qrCodeNotFound();
}
}
image.close();
}
public abstract void qrCodeNotFound();
public abstract void onQRCodeFound(Result result);
}