Skip to content

[camera_android, camera_android_camerax, camera_avfoundation] Add setJpegImageQuality#11616

Open
Bolling88 wants to merge 2 commits intoflutter:mainfrom
Bolling88:set-jpeg-quality
Open

[camera_android, camera_android_camerax, camera_avfoundation] Add setJpegImageQuality#11616
Bolling88 wants to merge 2 commits intoflutter:mainfrom
Bolling88:set-jpeg-quality

Conversation

@Bolling88
Copy link
Copy Markdown
Contributor

@Bolling88 Bolling88 commented Apr 30, 2026

Implements the setJpegImageQuality API (landed in the platform interface via #11454) across all camera platform implementation packages, allowing control of JPEG compression quality (1-100) for still image capture.

This is the follow-up implementation PR as requested in #11155; it does not include camera_platform_interface changes. The app-facing camera package will be submitted in a separate PR after these implementation packages are published.

Packages changed:

  • camera_android
  • camera_android_camerax
  • camera_avfoundation

Part of 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

Adds setJpegImageQuality(int quality) across all camera platform
implementations (Android, Android CameraX, iOS AVFoundation) and
the app-facing camera package. This allows controlling the JPEG
compression quality (1-100) for still image capture.

Platform interface changes were landed separately in flutter#11454.
Copy link
Copy Markdown

@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 adds the setJpegImageQuality method to the CameraController and implements it across the Android (Camera2 and CameraX) and iOS (AVFoundation) platform packages. Review feedback identifies a potential ClassCastException in the Android Camera2 implementation due to an incorrect type cast, the loss of flashMode state when recreating the ImageCapture use case in CameraX, and the unintended discarding of capture configurations in the iOS implementation.


@Override
public void updateBuilder(@NonNull CaptureRequest.Builder requestBuilder) {
requestBuilder.set(CaptureRequest.JPEG_QUALITY, (byte) currentSetting);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The CaptureRequest.JPEG_QUALITY key expects an Integer value (type Key<Integer>). Casting currentSetting to byte will result in a Byte object being passed to the requestBuilder.set method due to autoboxing. This will cause a ClassCastException at runtime because a Byte cannot be cast to an Integer.

Suggested change
requestBuilder.set(CaptureRequest.JPEG_QUALITY, (byte) currentSetting);
requestBuilder.set(CaptureRequest.JPEG_QUALITY, currentSetting);

Comment on lines +1156 to +1160
imageCapture = ImageCapture(
resolutionSelector: _presetResolutionSelector,
targetRotation: targetRotation,
jpegQuality: quality,
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

When recreating the ImageCapture instance to apply the new JPEG quality, the current flashMode is not passed to the constructor. This will cause the camera's flash setting to be reset to its default value whenever setJpegImageQuality is called.

    imageCapture = ImageCapture(
      resolutionSelector: _presetResolutionSelector,
      targetRotation: targetRotation,
      flashMode: flashMode,
      jpegQuality: quality,
    );

Comment on lines +724 to +729
settings = AVCapturePhotoSettings(format: [
AVVideoCodecKey: AVVideoCodecType.jpeg,
AVVideoCompressionPropertiesKey: [
AVVideoQualityKey: CGFloat(imageQuality) / 100.0
],
])
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Reassigning the settings variable here discards any configuration previously applied to the AVCapturePhotoSettings object. For example, settings like photoQualityPrioritization (which is typically set at the beginning of the takePicture method in this plugin) will be lost when imageQuality < 100. It is recommended to initialize settings with the correct format at the start of the takePicture method instead of reassigning it mid-flow.

The app-facing camera package should be submitted as a separate
follow-up PR after the implementation packages are published.
This removes the dependency_overrides that were blocking merge.
@Bolling88 Bolling88 changed the title [camera] Add setJpegImageQuality for JPEG compression control [camera_android, camera_android_camerax, camera_avfoundation] Add setJpegImageQuality Apr 30, 2026
@stuartmorgan-g stuartmorgan-g added triage-ios Should be looked at in iOS triage triage-android Should be looked at in Android triage federated: partial_changes PR that contains changes for only a single package of a federated plugin change labels May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

federated: partial_changes PR that contains changes for only a single package of a federated plugin change p: camera platform-android platform-ios platform-macos triage-android Should be looked at in Android triage triage-ios Should be looked at in iOS triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants