Skip to content

Scale high-pixel-ratio images with BoxFit.none/BoxFit.scaleDown correctly - #20791

Merged
Hixie merged 6 commits into
flutter:masterfrom
sir-boformer:image-scale-fix
Sep 6, 2018
Merged

Hixie merged 6 commits into
flutter:masterfrom
sir-boformer:image-scale-fix

Conversation

@sir-boformer

@sir-boformer sir-boformer commented Aug 19, 2018 •

Copy link
Copy Markdown
Contributor

Fixes #18682.

paintImage is used to paint BoxDecoration background images and Image widgets. This PR adds a new scale parameter so that the method can take into account the image scale (how many image pixels equal one logical pixel) so that 2.0x/3.0x variants are rendered correctly.

@sir-boformer sir-boformer changed the title WIP Scale high-pixel-ratio images with BoxFit.none/BoxFit.scaleDown correctly Scale high-pixel-ratio images with BoxFit.none/BoxFit.scaleDown correctly Aug 19, 2018
@sir-boformer

Copy link
Copy Markdown
Contributor Author

@Hixie This is ready for review.

I added a few unit tests to test the correct scaling and positioning of images on the canvas, with different fit and scale values. It's almost impossible to test every combination of scale, alignment, fit and rect. Previously there were no tests at all...

After all golden tests were not required, a TestCanvas works perfectly.

Here is a screenshot of the example application from the issue, which is now working correctly:

Plus a few other configurations which are working correctly as before:

for (double scale = 1.0; scale <= 4.0; scale += 1.0) {
final TestCanvas canvas = new TestCanvas(<Invocation>[]);

final Rect outputRect = Rect.fromLTWH(30.0, 30.0, 250.0, 250.0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Please use new for a few more days while we await having a lint to remove all news at once. (We want to be consistent in the meantime.)

@Hixie

Hixie commented Aug 29, 2018

Copy link
Copy Markdown
Contributor

This looks great. Thanks for your contribution! If you could make the tiny fix mentioned, we can land it! Thanks!

@sir-boformer

Copy link
Copy Markdown
Contributor Author

@Hixie new keywords added

@sir-boformer

Copy link
Copy Markdown
Contributor Author

@Hixie This has been here for a while. Can you merge it? I'm afraid that if you deicide to remove all new keywords, merging will become a lot more difficult.

@Hixie

Hixie commented Sep 5, 2018

Copy link
Copy Markdown
Contributor

Yup! Sorry about the delay!

@Hixie

Hixie commented Sep 5, 2018

Copy link
Copy Markdown
Contributor

(Just need to wait for the tree to be green. Looks like we've had some bad commits recently.)

@Hixie
Hixie merged commit a4838a2 into flutter:master Sep 6, 2018
@Hixie

Hixie commented Sep 6, 2018

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BoxFit.none does not take into account image scale, images always pixelated and scaled incorrectly

3 participants