Skip to content

Commit 48c9498

Browse files
authored
[camera_android_camerax] Fix incorrectly rotated captured photos (#9498)
Changes the target rotation of captured images to match that of the default display at the time of capture. This ensures that the photo's orientation is upright. This in turn fixes the rotation of the thumbnail previewing a captured photo (the thumbnail was never rotated incorrectly, just the image itself). Fixes flutter/flutter#169876. ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 57bbc9e commit 48c9498

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

packages/camera/camera_android_camerax/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.6.19
2+
3+
* Changes target rotation of captured images to current default display rotation to fix captured
4+
photo orientation to upright.
5+
16
## 0.6.18+3
27

38
* Fixes incorrect camera preview mirroring for front cameras of devices using the Impeller backend.

packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ class AndroidCameraCameraX extends CameraPlatform {
392392
// Configure ImageCapture instance.
393393
imageCapture = proxy.newImageCapture(
394394
resolutionSelector: presetResolutionSelector,
395-
/* use CameraX default target rotation */ targetRotation: null,
395+
/* use CameraX default target rotation */ targetRotation:
396+
await deviceOrientationManager.getDefaultDisplayRotation(),
396397
);
397398

398399
// Configure ImageAnalysis instance.
@@ -966,9 +967,9 @@ class AndroidCameraCameraX extends CameraPlatform {
966967
await imageCapture!.setFlashMode(CameraXFlashMode.off);
967968
}
968969

969-
// Set target rotation to default CameraX rotation only if capture
970-
// orientation not locked.
971-
if (!captureOrientationLocked && shouldSetDefaultRotation) {
970+
// Set target rotation to the current default CameraX rotation if
971+
// the capture orientation is not locked.
972+
if (!captureOrientationLocked) {
972973
await imageCapture!.setTargetRotation(
973974
await deviceOrientationManager.getDefaultDisplayRotation(),
974975
);

packages/camera/camera_android_camerax/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: camera_android_camerax
22
description: Android implementation of the camera plugin using the CameraX library.
33
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android_camerax
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
5-
version: 0.6.18+3
5+
version: 0.6.19
66

77
environment:
88
sdk: ^3.7.0

packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3488,7 +3488,7 @@ void main() {
34883488
);
34893489

34903490
test(
3491-
'takePicture sets ImageCapture target rotation to currrent photo rotation when orientation unlocked',
3491+
'takePicture sets ImageCapture target rotation as expected when orientation locked or unlocked',
34923492
() async {
34933493
final AndroidCameraCameraX camera = AndroidCameraCameraX();
34943494
final MockImageCapture mockImageCapture = MockImageCapture();
@@ -3531,7 +3531,7 @@ void main() {
35313531
// Orientation is unlocked and plugin does not need to set default target
35323532
// rotation manually.
35333533
await camera.takePicture(cameraId);
3534-
verifyNever(mockImageCapture.setTargetRotation(any));
3534+
verify(mockImageCapture.setTargetRotation(defaultTargetRotation));
35353535

35363536
// Orientation is locked and plugin does not need to set default target
35373537
// rotation manually.

0 commit comments

Comments
 (0)