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

[image_picker]Fixed losing transparency of PNGs#742

Merged
mklim merged 6 commits intoflutter:masterfrom
andreidiaconu:master
Feb 28, 2019
Merged

[image_picker]Fixed losing transparency of PNGs#742
mklim merged 6 commits intoflutter:masterfrom
andreidiaconu:master

Conversation

@andreidiaconu
Copy link
Contributor

When the user picks a png that has transparent pixels, these are then lost (made black). This was caused by always saving the image as JPEG when resizing.

At first I always saved the image as PNG, but that did not work very well for Android, where the JPEG format carried important rotation (EXIF) information. So for Android I am deciding the output format based on the file extension. For iOS things are a bit simpler and we can just always save as png.

@andreidiaconu andreidiaconu changed the title Fixed losing transparency of PNGs Fixed losing transparency of PNGs (imagepicker) Aug 27, 2018
@andreidiaconu andreidiaconu changed the title Fixed losing transparency of PNGs (imagepicker) Fixed losing transparency of PNGs (image_picker) Aug 27, 2018
@Hixie
Copy link
Contributor

Hixie commented Oct 30, 2018

@roughike would you mind reviewing this? You seem to have had the most impact on this plugin in recent months. :-)

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

Googlers can find more info about SignCLA and this PR by following this link.

@googlebot
Copy link

CLAs look good, thanks!

Googlers can find more info about SignCLA and this PR by following this link.

* commit 'd0b3d38a7c23e2129994b4d78663212be1a8a9f0':
  Fixed losing transparency of PNGs
@mehmetf mehmetf removed their request for review February 18, 2019 14:08
@cyanglaz cyanglaz changed the title Fixed losing transparency of PNGs (image_picker) [image_picker]Fixed losing transparency of PNGs (image_picker) Feb 23, 2019
@cyanglaz cyanglaz changed the title [image_picker]Fixed losing transparency of PNGs (image_picker) [image_picker]Fixed losing transparency of PNGs Feb 23, 2019
Copy link
Contributor

@mklim mklim left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution and your patience! If you don't have time to keep working on this, please let us know and somebody from our team can shepherd this PR forward.

Bitmap scaledBmp = Bitmap.createScaledBitmap(bmp, width.intValue(), height.intValue(), false);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
scaledBmp.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
boolean isPNG = path.toLowerCase().endsWith("png");
Copy link
Contributor

Choose a reason for hiding this comment

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

This covers almost everything, but I think there may still be some edge cases where the image may have transparent pixels that are lost without the filename necessarily ending in png. What do you think about instead casing off of if the bitmap supports transparency? There's Bitmap#hasAlpha().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a great suggestion. Thanks for reviewing and proposing a better alternative. Do you know if there is something similar we can use on iOS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For iOS I see there is this: https://developer.apple.com/documentation/coregraphics/1455401-cgimagegetalphainfo?language=objc - I will update the PR. Thanks again for jumping in 💯

Determine if a file needs to be saved as PNG by looking at the alpha channel on Android
Determine if a file needs to be saved as PNG by looking at the alpha channel on iOS
Copy link
Contributor

@mklim mklim left a comment

Choose a reason for hiding this comment

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

lgtm

Thank you again for the fix!

@mklim mklim added the submit queue The Flutter team is in the process of landing this PR. label Feb 28, 2019
@mklim mklim merged commit 9f3997b into flutter:master Feb 28, 2019
mklim pushed a commit that referenced this pull request Feb 28, 2019
romaluca pushed a commit to romaluca/plugins that referenced this pull request Mar 6, 2019
When the user picks a png that has transparent pixels, these are then lost (made black). This was caused by always saving the image as JPEG when resizing.

Determine if a file needs to be saved as PNG by looking at the alpha channel.
romaluca pushed a commit to romaluca/plugins that referenced this pull request Mar 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bugfix cla: yes submit queue The Flutter team is in the process of landing this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants