Skip to content

Commit 4f50116

Browse files
p30arenabparrishMines
authored andcommitted
[camera] Fixes #28350 (flutter#1261)
1 parent c6b16d9 commit 4f50116

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.4.2
2+
3+
* Add sensor orientation value to `CameraDescription`.
4+
15
## 0.4.1
26

37
* Camera methods are ran in a background thread on iOS.

android/src/main/java/io/flutter/plugins/camera/CameraPlugin.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ public void onMethodCall(MethodCall call, final Result result) {
164164
cameraManager.getCameraCharacteristics(cameraName);
165165
details.put("name", cameraName);
166166
@SuppressWarnings("ConstantConditions")
167+
int sensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
168+
details.put("sensorOrientation", sensorOrientation);
169+
167170
int lensFacing = characteristics.get(CameraCharacteristics.LENS_FACING);
168171
switch (lensFacing) {
169172
case CameraMetadata.LENS_FACING_FRONT:

ios/Classes/CameraPlugin.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ - (void)handleMethodCallAsync:(FlutterMethodCall *)call result:(FlutterResult)re
670670
[reply addObject:@{
671671
@"name" : [device uniqueID],
672672
@"lensFacing" : lensFacing,
673+
@"sensorOrientation" : @90,
673674
}];
674675
}
675676
result(reply);

lib/camera.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Future<List<CameraDescription>> availableCameras() async {
5858
return CameraDescription(
5959
name: camera['name'],
6060
lensDirection: _parseCameraLensDirection(camera['lensFacing']),
61+
sensorOrientation: camera['sensorOrientation'],
6162
);
6263
}).toList();
6364
} on PlatformException catch (e) {
@@ -66,11 +67,20 @@ Future<List<CameraDescription>> availableCameras() async {
6667
}
6768

6869
class CameraDescription {
69-
CameraDescription({this.name, this.lensDirection});
70+
CameraDescription({this.name, this.lensDirection, this.sensorOrientation});
7071

7172
final String name;
7273
final CameraLensDirection lensDirection;
7374

75+
/// Clockwise angle through which the output image needs to be rotated to be upright on the device screen in its native orientation.
76+
///
77+
/// **Range of valid values:**
78+
/// 0, 90, 180, 270
79+
///
80+
/// On Android, also defines the direction of rolling shutter readout, which
81+
/// is from top to bottom in the sensor's coordinate system.
82+
final int sensorOrientation;
83+
7484
@override
7585
bool operator ==(Object o) {
7686
return o is CameraDescription &&
@@ -85,7 +95,7 @@ class CameraDescription {
8595

8696
@override
8797
String toString() {
88-
return '$runtimeType($name, $lensDirection)';
98+
return '$runtimeType($name, $lensDirection, $sensorOrientation)';
8999
}
90100
}
91101

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: camera
22
description: A Flutter plugin for getting information about and controlling the
33
camera on Android and iOS. Supports previewing the camera feed, capturing images, capturing video,
44
and streaming image buffers to dart.
5-
version: 0.4.1
5+
version: 0.4.2
66
authors:
77
- Flutter Team <[email protected]>
88
- Luigi Agosti <[email protected]>

0 commit comments

Comments
 (0)