Skip to content

Commit 942f1bd

Browse files
authored
[camera_platform_interface] Adds support for setting the image file format (flutter#5593)
Part of flutter#4586
1 parent 9186a1f commit 942f1bd

File tree

9 files changed

+80
-3
lines changed

9 files changed

+80
-3
lines changed

packages/camera/camera_platform_interface/AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,4 @@ Aleksandr Yurkovskiy <sanekyy@gmail.com>
6464
Anton Borries <mail@antonborri.es>
6565
Alex Li <google@alexv525.com>
6666
Rahul Raj <64.rahulraj@gmail.com>
67+
Mairramer <mairramer.dasilva28@hotmail.com>

packages/camera/camera_platform_interface/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 2.7.0
22

3+
* Adds support for setting the image file format. See `CameraPlatform.setImageFileFormat`.
34
* Updates minimum supported SDK version to Flutter 3.10/Dart 3.0.
45

56
## 2.6.0

packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,17 @@ class MethodChannelCamera extends CameraPlatform {
529529
);
530530
}
531531

532+
@override
533+
Future<void> setImageFileFormat(int cameraId, ImageFileFormat format) {
534+
return _channel.invokeMethod<void>(
535+
'setImageFileFormat',
536+
<String, dynamic>{
537+
'cameraId': cameraId,
538+
'fileFormat': format.name,
539+
},
540+
);
541+
}
542+
532543
@override
533544
Widget buildPreview(int cameraId) {
534545
return Texture(textureId: cameraId);

packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,12 @@ abstract class CameraPlatform extends PlatformInterface {
298298
Future<void> dispose(int cameraId) {
299299
throw UnimplementedError('dispose() is not implemented.');
300300
}
301+
302+
/// Sets the output image file format for the selected camera.
303+
///
304+
// TODO(bmparr): This is only supported on iOS. See
305+
// https://github.com/flutter/flutter/issues/139588
306+
Future<void> setImageFileFormat(int cameraId, ImageFileFormat format) {
307+
throw UnimplementedError('setImageFileFormat() is not implemented.');
308+
}
301309
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
/// The format in which images should be returned from the camera.
6+
enum ImageFileFormat {
7+
/// The JPEG format.
8+
jpeg,
9+
10+
/// The HEIF format.
11+
///
12+
/// HEIF is a file format name that refers to High Efficiency Image Format
13+
/// (HEIF). For iOS, this is only supported on versions 11+.
14+
heif,
15+
}

packages/camera/camera_platform_interface/lib/src/types/types.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export 'camera_image_data.dart';
88
export 'exposure_mode.dart';
99
export 'flash_mode.dart';
1010
export 'focus_mode.dart';
11+
export 'image_file_format.dart';
1112
export 'image_format_group.dart';
1213
export 'media_settings.dart';
1314
export 'resolution_preset.dart';

packages/camera/camera_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/camera/camera
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 2.6.0
7+
version: 2.7.0
88

99
environment:
1010
sdk: ">=3.0.0 <4.0.0"

packages/camera/camera_platform_interface/test/events/camera_event_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void main() {
3131
'exposureMode': 'auto',
3232
'exposurePointSupported': true,
3333
'focusMode': 'auto',
34-
'focusPointSupported': true
34+
'focusPointSupported': true,
3535
});
3636

3737
expect(event.cameraId, 1);

packages/camera/camera_platform_interface/test/method_channel/method_channel_camera_test.dart

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,46 @@ void main() {
11541154
isMethodCall('stopImageStream', arguments: null),
11551155
]);
11561156
});
1157+
1158+
test('Should set the ImageFileFormat to heif', () async {
1159+
// Arrange
1160+
final MethodChannelMock channel = MethodChannelMock(
1161+
channelName: 'plugins.flutter.io/camera',
1162+
methods: <String, dynamic>{'setImageFileFormat': 'heif'},
1163+
);
1164+
1165+
// Act
1166+
await camera.setImageFileFormat(cameraId, ImageFileFormat.heif);
1167+
1168+
// Assert
1169+
expect(channel.log, <Matcher>[
1170+
isMethodCall('setImageFileFormat', arguments: <String, Object?>{
1171+
'cameraId': cameraId,
1172+
'fileFormat': 'heif',
1173+
}),
1174+
]);
1175+
});
1176+
1177+
test('Should set the ImageFileFormat to jpeg', () async {
1178+
// Arrange
1179+
final MethodChannelMock channel = MethodChannelMock(
1180+
channelName: 'plugins.flutter.io/camera',
1181+
methods: <String, dynamic>{
1182+
'setImageFileFormat': 'jpeg',
1183+
},
1184+
);
1185+
1186+
// Act
1187+
await camera.setImageFileFormat(cameraId, ImageFileFormat.jpeg);
1188+
1189+
// Assert
1190+
expect(channel.log, <Matcher>[
1191+
isMethodCall('setImageFileFormat', arguments: <String, Object?>{
1192+
'cameraId': cameraId,
1193+
'fileFormat': 'jpeg',
1194+
}),
1195+
]);
1196+
});
11571197
});
11581198
});
11591199
}

0 commit comments

Comments
 (0)