Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull final Result result)
}
break;
}
case "setPointOfInterest":
{
result.notImplemented();
break;
}
case "dispose":
{
if (camera != null) {
Expand Down
14 changes: 11 additions & 3 deletions packages/camera/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,17 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
);
} else {
return AspectRatio(
aspectRatio: controller.value.aspectRatio,
child: CameraPreview(controller),
);
aspectRatio: controller.value.aspectRatio,
child: GestureDetector(
child: CameraPreview(controller),
onTapUp: (TapUpDetails details) {
final RenderBox box = context.findRenderObject();
final Offset localPoint =
box.globalToLocal(details.globalPosition);
final Offset scaledPoint =
localPoint.scale(1 / box.size.width, 1 / box.size.height);
controller.setPointOfInterest(scaledPoint);
}));
}
}

Expand Down
22 changes: 22 additions & 0 deletions packages/camera/ios/Classes/CameraPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,28 @@ - (void)handleMethodCallAsync:(FlutterMethodCall *)call result:(FlutterResult)re
});
[cam start];
}
} else if ([@"setPointOfInterest" isEqualToString:call.method]) {
NSNumber *offsetX = call.arguments[@"offsetX"];
NSNumber *offsetY = call.arguments[@"offsetY"];

NSError *error = nil;
[_camera.captureDevice lockForConfiguration:&error];
if (error) {
result([error flutterError]);
} else {
if ([_camera.captureDevice isFocusPointOfInterestSupported]) {
_camera.captureDevice.focusPointOfInterest =
CGPointMake(offsetY.floatValue, 1 - offsetX.floatValue);
[_camera.captureDevice setFocusMode:AVCaptureFocusModeContinuousAutoFocus];
}
if ([_camera.captureDevice isExposurePointOfInterestSupported]) {
_camera.captureDevice.exposurePointOfInterest =
CGPointMake(offsetY.floatValue, 1 - offsetX.floatValue);
[_camera.captureDevice setExposureMode:AVCaptureExposureModeContinuousAutoExposure];
}
[_camera.captureDevice unlockForConfiguration];
result(@{});
}
} else if ([@"startImageStream" isEqualToString:call.method]) {
[_camera startImageStreamWithMessenger:_messenger];
result(nil);
Expand Down
20 changes: 20 additions & 0 deletions packages/camera/lib/camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,26 @@ class CameraController extends ValueNotifier<CameraValue> {
}
}

/// Sets the auto focus and auto exposure point.
///
/// Throws a [CameraException] if the call fails.
Future<Null> setPointOfInterest(Offset offset) async {
if (!value.isInitialized || _isDisposed) {
throw CameraException(
'Uninitialized CameraController.',
'takePicture was called on uninitialized CameraController',
);
}
try {
await _channel.invokeMethod(
'setPointOfInterest',
<String, dynamic>{'offsetX': offset.dx, 'offsetY': offset.dy},
);
} on PlatformException catch (e) {
throw CameraException(e.code, e.message);
}
}

/// Releases the resources of this camera.
@override
Future<void> dispose() async {
Expand Down