-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[camera] Add setImageQuality for JPEG compression control #11155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,9 @@ class CameraValue { | |
| this.isPreviewPaused = false, | ||
| this.previewPauseOrientation, | ||
| this.videoStabilizationMode = VideoStabilizationMode.off, | ||
| // An initializing formal isn't possible here: named parameters can't be | ||
| // private, and `isRecordingPaused` is a derived getter, not a stored field. | ||
| // ignore: prefer_initializing_formals | ||
| }) : _isRecordingPaused = isRecordingPaused; | ||
|
|
||
| /// Creates a new camera controller state for an uninitialized controller. | ||
|
|
@@ -969,6 +972,26 @@ class CameraController extends ValueNotifier<CameraValue> { | |
| } | ||
| } | ||
|
|
||
| /// Sets the JPEG compression quality for still image capture. | ||
| /// | ||
| /// This only applies to images captured in JPEG format. | ||
| /// The [quality] must be between 1 (lowest) and 100 (highest). | ||
| /// | ||
| /// This is a best-effort setting: platforms that do not support controlling | ||
| /// the JPEG quality ignore it rather than throwing. See | ||
| /// https://github.com/flutter/flutter/issues/191790 for the current state of | ||
| /// platform support. | ||
| Future<void> setJpegImageQuality(int quality) async { | ||
| if (quality < 1 || quality > 100) { | ||
| throw ArgumentError.value(quality, 'quality', 'Must be between 1 and 100.'); | ||
| } | ||
| try { | ||
| await CameraPlatform.instance.setJpegImageQuality(_cameraId, quality); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bparrishMines I just looked at the platform interface PR and the default implementation throws an unimplemented error, but there's no support query API. That's not a valid combination for new APIs, because there's no way for a client to know if it's safe to call this method. Either the default needs to be a no-op, or there needs to be a support query that's plumbed through this layer, with clear docs about checking before calling this.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Went with the no-op default. Opened #12123 to change it in the platform interface. Once that lands and publishes I'll bump the constraint here to ^2.13.1 and add a doc note that it's best-effort and ignored where it's not supported. Sounds good?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I agree. I didn't want to add an API to query for it because I expected this to be a feature that could be implemented on each platform. (e.g. like adding an API query for Assuming we don't have plans to implement on windows or web in the near future, an unimplemented error or a noop are neither ideal solutions. I would prefer that we go with the noop and create an issue to add support for web and windows. Then add the link to the issue in the app-facing plugin so that users can check when support has been added. Therefore the documentation won't cause confusion if we forget to update it after adding support. |
||
| } on PlatformException catch (e) { | ||
| throw CameraException(e.code, e.message); | ||
| } | ||
| } | ||
|
|
||
| /// Check whether the camera platform supports image streaming. | ||
| bool supportsImageStreaming() => CameraPlatform.instance.supportsImageStreaming(); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,11 +4,11 @@ description: A Flutter plugin for controlling the camera. Supports previewing | |
| Dart. | ||
| repository: https://github.com/flutter/packages/tree/main/packages/camera/camera | ||
| issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22 | ||
| version: 0.12.0+2 | ||
| version: 0.12.1 | ||
|
|
||
| environment: | ||
| sdk: ^3.10.0 | ||
| flutter: ">=3.38.0" | ||
| sdk: ^3.12.0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like yes! |
||
| flutter: ">=3.44.0" | ||
|
|
||
| flutter: | ||
| plugin: | ||
|
|
@@ -21,9 +21,9 @@ flutter: | |
| default_package: camera_web | ||
|
|
||
| dependencies: | ||
| camera_android_camerax: ^0.7.0 | ||
| camera_avfoundation: ^0.10.0 | ||
| camera_platform_interface: ^2.12.0 | ||
| camera_android_camerax: ^0.7.4 | ||
| camera_avfoundation: ^0.10.2 | ||
| camera_platform_interface: ^2.13.1 | ||
| camera_web: ^0.3.3 | ||
| flutter: | ||
| sdk: flutter | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flyby comment while responding to CICD request: With private named parameters it can be, depends on what version of Dart this is on.