Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit b25fe88

Browse files
committed
expose auto exposure and auto focus point of interest functionality (iOS only)
1 parent ce3a913 commit b25fe88

File tree

4 files changed

+58
-3
lines changed

4 files changed

+58
-3
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ public void onMethodCall(MethodCall call, final Result result) {
199199
camera.stopVideoRecording(result);
200200
break;
201201
}
202+
case "setPointOfInterest":
203+
{
204+
result.notImplemented();
205+
break;
206+
}
202207
case "dispose":
203208
{
204209
if (camera != null) {

packages/camera/example/lib/main.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,17 @@ class _CameraExampleHomeState extends State<CameraExampleHome> {
9595
);
9696
} else {
9797
return new AspectRatio(
98-
aspectRatio: controller.value.aspectRatio,
99-
child: new CameraPreview(controller),
100-
);
98+
aspectRatio: controller.value.aspectRatio,
99+
child: GestureDetector(
100+
child: new CameraPreview(controller),
101+
onTapUp: (TapUpDetails details) {
102+
final RenderBox box = context.findRenderObject();
103+
final Offset localPoint =
104+
box.globalToLocal(details.globalPosition);
105+
final Offset scaledPoint =
106+
localPoint.scale(1 / box.size.width, 1 / box.size.height);
107+
controller.setPointOfInterest(scaledPoint);
108+
}));
101109
}
102110
}
103111

packages/camera/ios/Classes/CameraPlugin.m

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,28 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
492492
});
493493
[cam start];
494494
}
495+
} else if ([@"setPointOfInterest" isEqualToString:call.method]) {
496+
NSNumber *offsetX = call.arguments[@"offsetX"];
497+
NSNumber *offsetY = call.arguments[@"offsetY"];
498+
499+
NSError *error = nil;
500+
[_camera.captureDevice lockForConfiguration:&error];
501+
if (error) {
502+
result([error flutterError]);
503+
} else {
504+
if ([_camera.captureDevice isFocusPointOfInterestSupported]) {
505+
_camera.captureDevice.focusPointOfInterest =
506+
CGPointMake(offsetY.floatValue, 1 - offsetX.floatValue);
507+
[_camera.captureDevice setFocusMode:AVCaptureFocusModeContinuousAutoFocus];
508+
}
509+
if ([_camera.captureDevice isExposurePointOfInterestSupported]) {
510+
_camera.captureDevice.exposurePointOfInterest =
511+
CGPointMake(offsetY.floatValue, 1 - offsetX.floatValue);
512+
[_camera.captureDevice setExposureMode:AVCaptureExposureModeContinuousAutoExposure];
513+
}
514+
[_camera.captureDevice unlockForConfiguration];
515+
result(@{});
516+
}
495517
} else {
496518
NSDictionary *argsMap = call.arguments;
497519
NSUInteger textureId = ((NSNumber *)argsMap[@"textureId"]).unsignedIntegerValue;

packages/camera/lib/camera.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,26 @@ class CameraController extends ValueNotifier<CameraValue> {
335335
}
336336
}
337337

338+
/// Sets the auto focus and auto exposure point.
339+
///
340+
/// Throws a [CameraException] if the call fails.
341+
Future<Null> setPointOfInterest(Offset offset) async {
342+
if (!value.isInitialized || _isDisposed) {
343+
throw new CameraException(
344+
'Uninitialized CameraController.',
345+
'takePicture was called on uninitialized CameraController',
346+
);
347+
}
348+
try {
349+
await _channel.invokeMethod(
350+
'setPointOfInterest',
351+
<String, dynamic>{'offsetX': offset.dx, 'offsetY': offset.dy},
352+
);
353+
} on PlatformException catch (e) {
354+
throw new CameraException(e.code, e.message);
355+
}
356+
}
357+
338358
/// Releases the resources of this camera.
339359
@override
340360
Future<Null> dispose() async {

0 commit comments

Comments
 (0)