mirror of
https://github.com/flutter/packages.git
synced 2025-07-01 15:23:25 +08:00
[camerax] Add flash configuration for image capture (#3800)
Implements off, auto, and always flash configurations for image capture. Part of https://github.com/flutter/flutter/issues/120715.
This commit is contained in:
@ -1,3 +1,7 @@
|
|||||||
|
## 0.5.0+10
|
||||||
|
|
||||||
|
* Implements off, auto, and always flash mode configurations for image capture.
|
||||||
|
|
||||||
## 0.5.0+9
|
## 0.5.0+9
|
||||||
|
|
||||||
* Marks all Dart-wrapped Android native classes as `@immutable`.
|
* Marks all Dart-wrapped Android native classes as `@immutable`.
|
||||||
|
@ -35,7 +35,7 @@ Any specified `ResolutionPreset` wll go unused in favor of CameraX defaults and
|
|||||||
|
|
||||||
### Flash mode configuration \[[Issue #120715][120715]\]
|
### Flash mode configuration \[[Issue #120715][120715]\]
|
||||||
|
|
||||||
`setFlashMode` is unimplemented.
|
Calling `setFlashMode` with mode `FlashMode.torch` currently does nothing.
|
||||||
|
|
||||||
### Exposure mode, point, & offset configuration \[[Issue #120468][120468]\]
|
### Exposure mode, point, & offset configuration \[[Issue #120468][120468]\]
|
||||||
|
|
||||||
|
@ -104,6 +104,9 @@ class AndroidCameraCameraX extends CameraPlatform {
|
|||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
ImageCapture? imageCapture;
|
ImageCapture? imageCapture;
|
||||||
|
|
||||||
|
/// The flash mode currently configured for [imageCapture].
|
||||||
|
int? _currentFlashMode;
|
||||||
|
|
||||||
/// The [ImageAnalysis] instance that can be configured to analyze individual
|
/// The [ImageAnalysis] instance that can be configured to analyze individual
|
||||||
/// frames.
|
/// frames.
|
||||||
ImageAnalysis? imageAnalysis;
|
ImageAnalysis? imageAnalysis;
|
||||||
@ -459,13 +462,32 @@ class AndroidCameraCameraX extends CameraPlatform {
|
|||||||
/// [cameraId] is not used.
|
/// [cameraId] is not used.
|
||||||
@override
|
@override
|
||||||
Future<XFile> takePicture(int cameraId) async {
|
Future<XFile> takePicture(int cameraId) async {
|
||||||
// TODO(camsim99): Add support for flash mode configuration.
|
if (_currentFlashMode != null) {
|
||||||
// https://github.com/flutter/flutter/issues/120715
|
await imageCapture!.setFlashMode(_currentFlashMode!);
|
||||||
|
}
|
||||||
final String picturePath = await imageCapture!.takePicture();
|
final String picturePath = await imageCapture!.takePicture();
|
||||||
|
|
||||||
return XFile(picturePath);
|
return XFile(picturePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the flash mode for the selected camera.
|
||||||
|
@override
|
||||||
|
Future<void> setFlashMode(int cameraId, FlashMode mode) async {
|
||||||
|
switch (mode) {
|
||||||
|
case FlashMode.off:
|
||||||
|
_currentFlashMode = ImageCapture.flashModeOff;
|
||||||
|
break;
|
||||||
|
case FlashMode.auto:
|
||||||
|
_currentFlashMode = ImageCapture.flashModeAuto;
|
||||||
|
break;
|
||||||
|
case FlashMode.always:
|
||||||
|
_currentFlashMode = ImageCapture.flashModeOn;
|
||||||
|
break;
|
||||||
|
case FlashMode.torch:
|
||||||
|
// TODO(camsim99): Implement torch mode when CameraControl is wrapped.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Configures and starts a video recording. Returns silently without doing
|
/// Configures and starts a video recording. Returns silently without doing
|
||||||
/// anything if there is currently an active recording.
|
/// anything if there is currently an active recording.
|
||||||
@override
|
@override
|
||||||
|
@ -2,7 +2,7 @@ name: camera_android_camerax
|
|||||||
description: Android implementation of the camera plugin using the CameraX library.
|
description: Android implementation of the camera plugin using the CameraX library.
|
||||||
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android_camerax
|
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android_camerax
|
||||||
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
|
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
|
||||||
version: 0.5.0+9
|
version: 0.5.0+10
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.19.0 <4.0.0"
|
sdk: ">=2.19.0 <4.0.0"
|
||||||
|
@ -779,8 +779,6 @@ void main() {
|
|||||||
final AndroidCameraCameraX camera = AndroidCameraCameraX();
|
final AndroidCameraCameraX camera = AndroidCameraCameraX();
|
||||||
const String testPicturePath = 'test/absolute/path/to/picture';
|
const String testPicturePath = 'test/absolute/path/to/picture';
|
||||||
|
|
||||||
camera.processCameraProvider = MockProcessCameraProvider();
|
|
||||||
camera.cameraSelector = MockCameraSelector();
|
|
||||||
camera.imageCapture = MockImageCapture();
|
camera.imageCapture = MockImageCapture();
|
||||||
|
|
||||||
when(camera.imageCapture!.takePicture())
|
when(camera.imageCapture!.takePicture())
|
||||||
@ -791,6 +789,41 @@ void main() {
|
|||||||
expect(imageFile.path, equals(testPicturePath));
|
expect(imageFile.path, equals(testPicturePath));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('setFlashMode configures ImageCapture with expected flash mode',
|
||||||
|
() async {
|
||||||
|
final AndroidCameraCameraX camera = AndroidCameraCameraX();
|
||||||
|
const int cameraId = 22;
|
||||||
|
|
||||||
|
camera.imageCapture = MockImageCapture();
|
||||||
|
|
||||||
|
for (final FlashMode flashMode in FlashMode.values) {
|
||||||
|
await camera.setFlashMode(cameraId, flashMode);
|
||||||
|
|
||||||
|
int? expectedFlashMode;
|
||||||
|
switch (flashMode) {
|
||||||
|
case FlashMode.off:
|
||||||
|
expectedFlashMode = ImageCapture.flashModeOff;
|
||||||
|
break;
|
||||||
|
case FlashMode.auto:
|
||||||
|
expectedFlashMode = ImageCapture.flashModeAuto;
|
||||||
|
break;
|
||||||
|
case FlashMode.always:
|
||||||
|
expectedFlashMode = ImageCapture.flashModeOn;
|
||||||
|
break;
|
||||||
|
case FlashMode.torch:
|
||||||
|
// TODO(camsim99): Test torch mode when implemented.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (expectedFlashMode == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
await camera.takePicture(cameraId);
|
||||||
|
verify(camera.imageCapture!.setFlashMode(expectedFlashMode));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test('getMinExposureOffset returns expected exposure offset', () async {
|
test('getMinExposureOffset returns expected exposure offset', () async {
|
||||||
final AndroidCameraCameraX camera = AndroidCameraCameraX();
|
final AndroidCameraCameraX camera = AndroidCameraCameraX();
|
||||||
final MockCameraInfo mockCameraInfo = MockCameraInfo();
|
final MockCameraInfo mockCameraInfo = MockCameraInfo();
|
||||||
|
Reference in New Issue
Block a user