Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Conversation

@Xavjer
Copy link

@Xavjer Xavjer commented Sep 13, 2019

Description

Fixes the issue, that within image_picker when taking a picture on iOS in Portrait mode, the scaling did not work as intended (AspectRatio was flipped)

Related Issues

flutter/flutter#40334 => Will be fixed with this PR

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
    => No new unit tests added, as the existing should already cover this, but the image did not have the values that were returned from the channel.
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

@cyanglaz
Copy link
Contributor

@Xavjer Can we just flip the width and height for portrait pictures instead of using a completely different API? This change may be a bit risky until we set up a CI and write tests for this.

@cyanglaz
Copy link
Contributor

cyanglaz commented Sep 25, 2019

I created this PR for an alternative fix. Do you want to take a look? @Xavjer
#2106

@Xavjer
Copy link
Author

Xavjer commented Sep 25, 2019

@cyanglaz I was thinking about that too, but from my understanding this is the better way to create a thumbnail, as the resulting image has a better resolution (and memory/performance improvement, especially during the case that we have to rotate the image) and it get's rid of the "issue" to rotate the image first.

This is apple's recommended way, see: https://medium.com/@prafullkumar77/image-usage-memory-comparison-and-best-practices-in-ios-wwdc2018-4a8919019ae9
Or the WWDC2018 video referenced there https://developer.apple.com/videos/play/wwdc2018/219/

Your fix should work too, but I was trying to improve the code itself not only fix the issue.

CFDictionaryRef options = (__bridge CFDictionaryRef) @{
(id)kCGImageSourceCreateThumbnailWithTransform : @YES,
(id)kCGImageSourceCreateThumbnailFromImageAlways : @YES,
(id)kCGImageSourceThumbnailMaxPixelSize : MAX(maxWidth, maxHeight)
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that the behavior would be different here.
Imagine we have an image that we want to specify maxWidth to be 100 and height to be 400. The original image is very big say 2000 by 4000.
In our old implementation, the final image would be 100 * 200.
In this implementation, the final image would be 400 * 800.

Copy link
Author

Choose a reason for hiding this comment

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

You are right, that would happen in this solution. There is only a maxDimension which can be set with this, therefore your recommended way will probably be the correct solution. For my usecase, I want to reduce the imagesize for the larger side to be 1024, therefore that worked for my case.

@cyanglaz
Copy link
Contributor

Closing this PR and we will solve the issue with #2070
@Xavjer If think your solution is more for flutter/flutter#26191. If you are interested, you could create a PR to add a new method which generates a thumbnail for the image

@cyanglaz cyanglaz closed this Oct 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants