Repository navigation
[image_picker] Subsample large images when resizing on Android - #13038
Conversation
ImageResizer computed inSampleSize from a BitmapFactory.Options that had never been used for a decode, so its outWidth and outHeight were still zero and the sample size was always 1. Every resize with maxWidth or maxHeight decoded the full-size bitmap before scaling it down. Compute the sample size from the original dimensions that readFileDimensions already read. Fixes flutter/flutter#193036
There was a problem hiding this comment.
Code Review
This pull request updates the Android image resizer to subsample large images during decoding when resizing with maxWidth or maxHeight, refactoring calculateSampleSize to accept explicit dimensions and adding a unit test. Feedback on the changes points out a potential infinite loop and division-by-zero crash in calculateSampleSize if targetWidth or targetHeight is zero, suggesting a guard clause to handle this case.
|
This pull request is not mergeable in its current state, likely because of a merge conflict. Pre-submit CI jobs were not triggered. Pushing a new commit to this branch that resolves the issue will result in pre-submit jobs being scheduled. |
|
autosubmit label was removed for flutter/packages/13038, because This PR has not met approval requirements for merging. The PR author is not a member of flutter-hackers and needs 1 more review(s) in order to merge this PR.
|
|
autosubmit label was removed for flutter/packages/13038, because Pull request flutter/packages/13038 is not in a mergeable state. |
|
autosubmit label was removed for flutter/packages/13038, because This PR has not met approval requirements for merging. The PR author is not a member of flutter-hackers and needs 1 more review(s) in order to merge this PR.
|
|
@gmackall for second review |
…er#193840) flutter/packages@5620e65...951f2f7 2026-10-05 Hamidrezash1384@gmail.com [material_ui] Add scrollPadding property to DropdownMenuFormField (flutter/packages#12735) 2026-10-02 36861262+QuncCccccc@users.noreply.github.com [material_ui] Migrate M3 Motion template to use new gen_defaults (flutter/packages#13058) 2026-10-02 44747303+theprantadutta@users.noreply.github.com [cupertino_ui] Forward showDragHandle from showCupertinoSheet to CupertinoSheetRoute (flutter/packages#13011) 2026-10-02 105214765+HibaChamkhi@users.noreply.github.com [cupertino_ui] Fix CupertinoMagnifier focal point with custom size (flutter/packages#13029) 2026-10-02 katelovett@google.com [ci] Add material_ui and cupertino_ui to customer testing (flutter/packages#13114) 2026-10-02 36861262+QuncCccccc@users.noreply.github.com [material_ui] Add Material 3 Expressive migration skill (flutter/packages#12818) 2026-10-02 sethineelansh@gmail.com [video_player] Ignore late position updates after disposal (flutter/packages#12971) 2026-10-02 46639812+Gyeony95@users.noreply.github.com [material_ui] Remove unconditional dart:io import from about.dart (flutter/packages#12774) 2026-10-02 50643541+Mairramer@users.noreply.github.com [material_ui] Fix DropdownButtonFormField underline alignment at bottom (flutter/packages#12606) 2026-10-02 engine-flutter-autoroll@skia.org Roll Flutter from e89fd0a to d03768e (23 revisions) (flutter/packages#13111) 2026-10-02 dkwingsmt@users.noreply.github.com [material_ui] Migrate `Switch` API doc snippets to {@example} (batch 8) (flutter/packages#13052) 2026-10-02 45616602+NikhilKukreja26@users.noreply.github.com [url_launcher] Fix supportsCloseForLaunchMode to query close support (flutter/packages#12926) 2026-10-02 15619084+vashworth@users.noreply.github.com Redistribute iOS/macOS Suggested Reviewers (flutter/packages#13076) 2026-10-02 anilcan.cakir@gmail.com [image_picker] Subsample large images when resizing on Android (flutter/packages#13038) 2026-10-02 kevmoo@users.noreply.github.com [cupertino_ui] Remove redundant null arguments in Completer.complete (flutter/packages#13008) 2026-10-02 269567208+reidbaker-agent@users.noreply.github.com [repo] Update AGENTS.md with dependency allowance and versioning guidance (flutter/packages#12579) If this roll has caused a breakage, revert this CL and set the roller to dry run mode using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
ImageResizer.resizeImageIfNeededcreated a freshBitmapFactory.Optionsand passed it tocalculateSampleSize, which readoptions.outWidthandoptions.outHeight. That object had never been used for a decode, so both were 0 and the sample size was always 1: every resize withmaxWidthormaxHeightdecoded the full-size bitmap (about 48 MB for a 12 MP photo) before scaling it down. The original dimensions were already read byreadFileDimensions, into a differentOptions.This PR passes those original dimensions to
calculateSampleSizeinstead. The sample size stays the largest power of two that still decodes at least the target size, so the output dimensions are unchanged.The new
onResizeImageIfNeeded_whenDownscaling_shouldSubsampleFromOriginalSizetest resizes a 12x7 image to a width of 3 and checks the pixel decode usesinSampleSize == 2(before the fix it was 1) and that the output is still 3x2. This is not a regression: subsampling has never taken effect, sinceinSampleSizehas been 1 from when it was introduced in #3423, and before that the full image was decoded too.Fixes flutter/flutter#193036
Pre-Review Checklist
[shared_preferences]///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
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