8000 [camera] Expose auto exposure and auto focus point of interest functionality (iOS only) by fore5fire · Pull Request #709 · flutter/plugins · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[camera] Expose auto exposure and auto focus point of interest functionality (iOS only) #709

Closed
wants to merge 3 commits into from
Closed
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
8000
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ public void onMethodCall(MethodCall call, final Result result) {
camera.stopVideoRecording(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
8000
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,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 @@ -492,6 +492,28 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
});
[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 {
NSDictionary *argsMap = call.arguments;
NSUInteger textureId = ((NSNumber *)argsMap[@"textureId"]).unsignedIntegerValue;
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 @@ -335,6 +335,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<Null> dispose() async {
Expand Down
0