Skip to content

Fix Android default zoom ratio#316

Merged
jfversluis merged 2 commits into
mainfrom
jfversluis-fix-android-autofocus
Jun 30, 2026
Merged

Fix Android default zoom ratio#316
jfversluis merged 2 commits into
mainfrom
jfversluis-fix-android-autofocus

Conversation

@jfversluis

@jfversluis jfversluis commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Fix Android ZoomFactor mapping so the default value (0) resolves to 1x zoom, matching Apple/Windows behavior
  • Avoid using CameraX SetLinearZoom(0) as the default because on logical multi-camera devices such as Pixel 7 the minimum zoom ratio can select an ultrawide/fixed-focus physical camera
  • Keep higher ZoomFactor values mapped from 1x to the camera's max zoom ratio

Fixes #315.

Thanks @sbrunaugh for testing the first artifact. That ruled out the explicit continuous-AF approach and pointed back to the 0.8.2 → 0.9.0 regression. The key change in that range was the new Android zoom path: default ZoomFactor = 0 started calling SetLinearZoom(0), unlike 0.8.2 which never applied zoom and unlike Apple/Windows which treat 0 as 1x. On Pixel 7, CameraX minimum zoom can switch to the ultrawide/fixed-focus lens, which matches the blurry/no-continuous-focus behavior.

Once the updated PR build artifacts are available, please try the new artifacts and let us know whether the preview/scanning focus behavior is back to the 0.8.2 behavior on your Pixel 7.

Validation

  • dotnet test ZXing.Net.MAUI.Tests/ZXing.Net.MAUI.Tests.csproj --no-restore --verbosity minimal
  • dotnet build ZXing.Net.MAUI/ZXing.Net.MAUI.csproj -f net10.0-android --no-restore --verbosity minimal

Configure CameraX preview and image analysis capture requests to use continuous picture autofocus on Android so barcode scanning does not rely on device-specific default AF behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sbrunaugh

Copy link
Copy Markdown

Hi, tested artifact build \ci28429682816\ (0.999.0-ci28429682816) on a Pixel 7 running Android — unfortunately the autofocus behavior is identical to 0.10.x. The camera preview shows but focus does not continuously adjust; it behaves exactly like the regression we reported in #315.

For reference, 0.8.2 (on our \develop\ branch) still works correctly on the same device, so the regression is still present with this PR's changes.

Happy to test follow-up builds if you want to try a different approach. The fallback idea mentioned in #315 (periodic \CancelFocusAndMetering\ + \AutoFocus()\ for devices that don't honor \CONTINUOUS_PICTURE\ via \Camera2Interop) might be worth exploring.

Map Android ZoomFactor from 1x to max zoom instead of using CameraX linear zoom from the device minimum. On logical multi-camera devices such as Pixel 7, the minimum zoom can select an ultrawide/fixed-focus lens, which regressed autofocus behavior when the default ZoomFactor value was applied.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jfversluis jfversluis changed the title Fix Android continuous autofocus Fix Android default zoom ratio Jun 30, 2026
@jfversluis

Copy link
Copy Markdown
Collaborator Author

Thanks for testing the first build, @sbrunaugh. I took another hard look specifically at 0.8.2 → 0.9.0 since you confirmed 0.8.2 still works.

The likely regression is the Android zoom change added in that range: the default ZoomFactor = 0 was being applied with CameraX SetLinearZoom(0). On Pixel 7/logical multi-camera devices that can mean the minimum zoom ratio, which may select the ultrawide/fixed-focus physical camera. That would explain why continuous AF changes did not help.

I pushed an updated fix that maps Android ZoomFactor = 0 to 1x, matching Apple/Windows and the pre-zoom Android behavior. Once the new PR artifacts are available, could you try those and let us know whether the focus behavior matches 0.8.2 again?

@sbrunaugh

Copy link
Copy Markdown

@jfversluis that worked! Barcodes are scanning cleanly like in 0.8.2. I look forward to integrating this fix once it's merged.

@jfversluis jfversluis merged commit b267db1 into main Jun 30, 2026
4 checks passed
@jfversluis

Copy link
Copy Markdown
Collaborator Author

@sbrunaugh thanks! Should be released as 0.10.2 shortly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android: camera preview out of focus / blurry (no continuous autofocus in 0.9.0+)

2 participants