Skip to content

[camera] Add setImageQuality for JPEG compression control#11155

Open
Bolling88 wants to merge 9 commits intoflutter:mainfrom
Bolling88:fix-set-quality
Open

[camera] Add setImageQuality for JPEG compression control#11155
Bolling88 wants to merge 9 commits intoflutter:mainfrom
Bolling88:fix-set-quality

Conversation

@Bolling88
Copy link

@Bolling88 Bolling88 commented Mar 2, 2026

Adds setImageQuality(int quality) (1–100 scale) across the camera plugin ecosystem, allowing developers to control JPEG compression quality for still image capture. Users who do not call setImageQuality retain the platform's native default behavior.

Packages changed

Package Version Notes
camera_platform_interface 2.12.0 → 2.13.0 Abstract method + method channel impl
camera 0.12.0 → 0.12.1 CameraController.setImageQuality with 1–100 range validation
camera_android 0.10.10+15 → 0.10.11 JpegQualityFeature using CaptureRequest.JPEG_QUALITY (Camera2)
camera_android_camerax 0.7.0+1 → 0.7.1 Recreates ImageCapture via Builder.setJpegQuality; preserves locked capture orientation
camera_avfoundation 0.10.0+3 → 0.10.1 EXIF-preserving JPEG recompression via CGImageSource/CGImageDestination (ImageIO), gated on JPEG format only

Platform implementation details

  • Android (Camera2): New JpegQualityFeature sets CaptureRequest.JPEG_QUALITY on the capture request builder. Lazily registered so users who never call setImageQuality keep the device HAL's native default.
  • Android (CameraX): CameraX only supports setJpegQuality at ImageCapture construction time, so setImageQuality unbinds the current ImageCapture and recreates it with the requested quality. Locked capture orientation is preserved across recreation.
  • iOS (AVFoundation): When quality < 100 and format is JPEG, re-encodes using CGImageDestination with kCGImageDestinationLossyCompressionQuality, preserving all EXIF metadata from the original capture. HEIF captures are passed through unmodified.

Fixes flutter/flutter#183229

Pre-Review Checklist

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2

@google-cla
Copy link

google-cla bot commented Mar 2, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the setImageQuality method to control JPEG compression quality for still image captures across the camera plugin. The implementation is federated, with platform-specific logic for Android (Camera2 and CameraX) and iOS. The Android Camera2 implementation uses CaptureRequest.JPEG_QUALITY. The CameraX implementation recreates the ImageCapture use case to apply the quality setting, preserving any locked capture orientation. The iOS implementation re-encodes JPEG images to the specified quality while retaining EXIF metadata. The changes are accompanied by updates to the platform interface, method channels, and comprehensive tests for each platform.

Adds `setImageQuality(int quality)` (1-100 scale) across the camera
plugin ecosystem to allow developers to control JPEG compression
quality for still image capture. Users who do not call setImageQuality
retain the platform's native default behavior.

Implementation details per platform:
- Platform interface: abstract method + method channel implementation
- App-facing: CameraController.setImageQuality with range validation
- Android (Camera2): JpegQualityFeature using CaptureRequest.JPEG_QUALITY
- Android (CameraX): Recreates ImageCapture with Builder.setJpegQuality,
  preserving locked capture orientation
- iOS (AVFoundation): EXIF-preserving JPEG recompression via
  CGImageSource/CGImageDestination (ImageIO), gated on JPEG format only
@stuartmorgan-g
Copy link
Collaborator

Thanks for the contribution!

Pre-Review Checklist

In the future, please use our checklist rather than replacing it with one you have invented. Our checklist is standardized for a reason.

Related issues

Fixes flutter/flutter#60397

Please provide the actual issue this is related to. That's not even a camera issue.

Versions 0.7.1 (camera_android_camerax) and 0.10.1 (camera_avfoundation)
were already taken by upstream changes. Bumps to next minor and includes
upstream CHANGELOG entries.
@Bolling88
Copy link
Author

Thanks for the contribution!

Pre-Review Checklist

In the future, please use our checklist rather than replacing it with one you have invented. Our checklist is standardized for a reason.

Related issues

Fixes flutter/flutter#60397

Please provide the actual issue this is related to. That's not even a camera issue.

Sorry for that! My first contribution, and still learning!

Regarding the issue, I just took a placeholder and forgot to change it. This is rather a feature improvement than resolving an issue, but I found and linked a closed issue where one of the comments requested the possibility to set image quality. If that is not enough, can I just create a new issue?

@stuartmorgan-g
Copy link
Collaborator

This is rather a feature improvement than resolving an issue

As with almost every project, we track bug reports and feature requests in the same issue tracker.

but I found and linked a closed issue where one of the comments requested the possibility to set image quality. If that is not enough, can I just create a new issue?

An issue that was fixed seven years ago does not provide an explanation of what current use case needs new APIs. If there isn't an issue covering the use case you are trying to address, then you should file one.

@Bolling88
Copy link
Author

This is rather a feature improvement than resolving an issue

As with almost every project, we track bug reports and feature requests in the same issue tracker.

but I found and linked a closed issue where one of the comments requested the possibility to set image quality. If that is not enough, can I just create a new issue?

An issue that was fixed seven years ago does not provide an explanation of what current use case needs new APIs. If there isn't an issue covering the use case you are trying to address, then you should file one.

Thank you for your patience. I have created a new issue ticket that clearly explains the problem/feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[camera] Add API to control JPEG compression quality

2 participants