Skip to content

image_picker_android-v0.8.13+25

@anilcancakir anilcancakir tagged this 02 Oct 17:16
`ImageResizer.resizeImageIfNeeded` created a fresh `BitmapFactory.Options` and passed it to `calculateSampleSize`, which read `options.outWidth` and `options.outHeight`. That object had never been used for a decode, so both were 0 and the sample size was always 1: every resize with `maxWidth` or `maxHeight` decoded the full-size bitmap (about 48 MB for a 12 MP photo) before scaling it down. The original dimensions were already read by `readFileDimensions`, into a different `Options`.

This PR passes those original dimensions to `calculateSampleSize` instead. 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_shouldSubsampleFromOriginalSize` test resizes a 12x7 image to a width of 3 and checks the pixel decode uses `inSampleSize == 2` (before the fix it was 1) and that the output is still 3x2. This is not a regression: subsampling has never taken effect, since `inSampleSize` has been 1 from when it was introduced in #3423, and before that the full image was decoded too.

Fixes https://github.com/flutter/flutter/issues/193036

## Pre-Review Checklist

**Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot 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.

[^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.
Assets 2
Loading