Skip to content

QR codes not detecting on Samsung Galaxy A23, bitmapOrg Bitmap captures wrong area of camera feed (with proposed fix) #8

@cameronharvey92

Description

@cameronharvey92

Hello there!

Using either version 1.2.0 or 1.4.0 of your library, QR codes are not detectable within the "detection area" on a Samsung Galaxy A23, running Android 14.

As per the Android quirks in the readme, this devices does not produce a distorted result, but instead actually captures a different area of the camera feed.

So it can actually detect QR codes when the debugPreviewView is eventually pointed at it, but it is well outside of the detection area.

This seems to be an isolated device-specific issue, as similar things have been reported here and here, but I thought I would report this bug in case it wasn't. One of these links also indicates the Android version is irrelevant.

Incorrect result in portrait mode - captures an area to the top-right:
QR code not scanned - Portrait

Incorrect result in landscape mode - captures an area to the top-left:
QR code not scanned - Landscape

Proposed fix
I was originally going to say that it seems the result of BitmapUtils.getBitmap() is incorrect, and that this device may not be supported.

But for some strange reason, I was able to fix the issue simply by explicitly calling setTargetResolution() on the ImageAnalysis.Builder. Even random sizes seemed to work, e.g.

import android.util.Size;

ImageAnalysis imageAnalysis = new ImageAnalysis.Builder()
        .setTargetResolution(new Size(300, 300))  // <-- This line
        .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
         .build();
imageAnalysis.setAnalyzer(executor, analyzer);

I understand using previewView's resolution would make more sense, and that device rotation issues / performance issues come to mind. So this also worked:

import android.util.Size;

int previewViewMinSize = Math.min(previewView.getWidth(), previewView.getHeight());  // <-- This line
ImageAnalysis imageAnalysis = new ImageAnalysis.Builder()
        .setTargetResolution(new Size(previewViewMinSize / 2, previewViewMinSize / 2))  // <-- This line
        .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
         .build();
imageAnalysis.setAnalyzer(executor, analyzer);

The results below look the same with either code snippet.

Either way, hopefully this issue is resolvable!

Cheers,
Cameron Harvey

Correct result - Portrait:
QR code scanned - Portrait

Correct result - Landscape:
QR code scanned - Landscape

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions