[image_picker]Fixed losing transparency of PNGs#742
Conversation
|
@roughike would you mind reviewing this? You seem to have had the most impact on this plugin in recent months. :-) |
|
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 Googlers can find more info about SignCLA and this PR by following this link. |
8935485 to
d0b3d38
Compare
|
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
mklim
left a comment
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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().
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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.

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.