@@ -19,11 +19,13 @@ @interface FLTSavePhotoDelegate : NSObject <AVCapturePhotoCaptureDelegate>
19
19
@property (readonly , nonatomic ) FlutterResult result;
20
20
@property (readonly , nonatomic ) CMMotionManager *motionManager;
21
21
@property (readonly , nonatomic ) AVCaptureDevicePosition cameraPosition;
22
+ @property (assign , nonatomic ) BOOL shouldAutoRotate;
22
23
23
24
- initWithPath : (NSString *)filename
24
25
result : (FlutterResult)result
25
26
motionManager : (CMMotionManager *)motionManager
26
- cameraPosition : (AVCaptureDevicePosition)cameraPosition ;
27
+ cameraPosition : (AVCaptureDevicePosition)cameraPosition
28
+ shouldAutoRotate : (BOOL )shouldAutoRotate ;
27
29
@end
28
30
29
31
@interface FLTImageStreamHandler : NSObject <FlutterStreamHandler>
@@ -52,13 +54,15 @@ @implementation FLTSavePhotoDelegate {
52
54
- initWithPath : (NSString *)path
53
55
result : (FlutterResult)result
54
56
motionManager : (CMMotionManager *)motionManager
55
- cameraPosition : (AVCaptureDevicePosition)cameraPosition {
57
+ cameraPosition : (AVCaptureDevicePosition)cameraPosition
58
+ shouldAutoRotate : (BOOL )shouldAutoRotate {
56
59
self = [super init ];
57
60
NSAssert (self, @" super init cannot be nil" );
58
61
_path = path;
59
62
_result = result;
60
63
_motionManager = motionManager;
61
64
_cameraPosition = cameraPosition;
65
+ _shouldAutoRotate = shouldAutoRotate;
62
66
selfReference = self;
63
67
return self;
64
68
}
@@ -90,6 +94,9 @@ - (void)captureOutput:(AVCapturePhotoOutput *)output
90
94
}
91
95
92
96
- (UIImageOrientation)getImageRotation {
97
+ if (!self.shouldAutoRotate ) {
98
+ return UIImageOrientationRight;
99
+ }
93
100
float const threshold = 45.0 ;
94
101
BOOL (^isNearValue)(float value1, float value2) = ^BOOL (float value1, float value2) {
95
102
return fabsf (value1 - value2) < threshold;
@@ -204,7 +211,13 @@ - (void)startVideoRecordingAtPath:(NSString *)path result:(FlutterResult)result;
204
211
- (void )stopVideoRecordingWithResult : (FlutterResult)result ;
205
212
- (void )startImageStreamWithMessenger : (NSObject <FlutterBinaryMessenger> *)messenger ;
206
213
- (void )stopImageStream ;
207
- - (void )captureToFile : (NSString *)filename result : (FlutterResult)result ;
214
+ // / Captures a photo and save to the specified file path.
215
+ // / @param filename The path where the photo should be saved to.
216
+ // / @param shouldAutoRotate Whether to automatically rotate the captured photo.
217
+ // / If enabled, Saves the EXIF data according to device accelerometer.
218
+ - (void )captureToFile : (NSString *)path
219
+ shouldAutoRotate : (BOOL )shouldAutoRotate
220
+ result : (FlutterResult)result ;
208
221
@end
209
222
210
223
@implementation FLTCam {
@@ -272,7 +285,9 @@ - (void)stop {
272
285
[_captureSession stopRunning ];
273
286
}
274
287
275
- - (void )captureToFile : (NSString *)path result : (FlutterResult)result {
288
+ - (void )captureToFile : (NSString *)path
289
+ shouldAutoRotate : (BOOL )shouldAutoRotate
290
+ result : (FlutterResult)result {
276
291
AVCapturePhotoSettings *settings = [AVCapturePhotoSettings photoSettings ];
277
292
if (_resolutionPreset == max) {
278
293
[settings setHighResolutionPhotoEnabled: YES ];
@@ -282,7 +297,8 @@ - (void)captureToFile:(NSString *)path result:(FlutterResult)result {
282
297
delegate: [[FLTSavePhotoDelegate alloc ] initWithPath: path
283
298
result: result
284
299
motionManager: _motionManager
285
- cameraPosition: _captureDevice.position]];
300
+ cameraPosition: _captureDevice.position
301
+ shouldAutoRotate: shouldAutoRotate]];
286
302
}
287
303
288
304
- (void )setCaptureSessionPreset : (ResolutionPreset)resolutionPreset {
@@ -882,7 +898,10 @@ - (void)handleMethodCallAsync:(FlutterMethodCall *)call result:(FlutterResult)re
882
898
NSUInteger textureId = ((NSNumber *)argsMap[@" textureId" ]).unsignedIntegerValue ;
883
899
884
900
if ([@" takePicture" isEqualToString: call.method]) {
885
- [_camera captureToFile: call.arguments[@" path" ] result: result];
901
+ BOOL shouldAutoRotate = [call.arguments[@" shouldAutoRotate" ] boolValue ];
902
+ [_camera captureToFile: call.arguments[@" path" ]
903
+ shouldAutoRotate: shouldAutoRotate
904
+ result: result];
886
905
} else if ([@" dispose" isEqualToString: call.method]) {
887
906
[_registry unregisterTexture: textureId];
888
907
[_camera close ];
0 commit comments