-
-
Notifications
You must be signed in to change notification settings - Fork 529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Appreciate UIImage.scale when decompressing images #42
Conversation
Change `targetSize` to use the same scale as `UIImage.size`. Also use `round` (to nearest) to convert scaled dimensions to integer rather than truncating the fractional part. Since sizes in iOS are expressed in logical points, not pixels, it is more natural to treat `targetSize` as logical points, so that decompressing an image of `image.size == CGSize(width: 400, height: 300)` and `image.scale == 2.0` down to `targetSize == CGSize(width: 200, height: 150)` would actually mean the same as `decompressImage(image, 0.5)` – rather than `decompressImage(image, 0.25)` which it did before this patch.
Hey @pyrtsa . I think I understand why you would want to express There are at least two ways to treat targetSize as points, and they produce different results:
It seems less ambiguous to express And |
That sounds fair enough. I think using a screen scale becomes problematic in the subtle scenario when there is an external screen attached (often with a scale different from How about doing the following change instead?
I'll modify the pull request accordingly. |
It's late, I can't think anymore ;)
|
This should make things a bit more intuitive to everyone: - If you don't set a `targetScale`, the scale of 1 is used, making the resulting image to have its `UIImage.size` correspond 1:1 to its resolution in pixels. - This has been the meaning of `targetSize` up to this day, but a bit confusingly so. - The only difference to the old behaviour is that the resulting `UIImage.scale` no longer depends on the input's scale, while `UIImage.size` now matches `targetSize`. - If you set a `targetScale` such as `UIScreen.mainScreen().scale`, then the resulting `UIImage` uses that as its `UIImage.scale`, meaning that its resolution in pixels is accordingly higher. In other words, `targetSize` defines (the maximum value for) `UIImage.size` and `targetScale` defines `UIImage.scale` (as is).
Sorry for the delay. This issue turned bikesheddy, which I'm sorry about and I don't like. Here's another attempt at making it better anyway. I find it unlikely to break existing code but it's a breaking change anyway: now there's a new parameter What do you think? |
It's ok, we're not in a hurry, thanks that you are investing your time :) It's not really a bikeshedding, the framework is already complete, and even though that change is small, it's still a breaking one. I understand how you would want If you want to treat About scale. Again, I'm very reluctant about adding |
Yes, this is exactly the bikeshedding I'm talking about – in other words, I don't want to take this discussion further. You're absolutely right that adding I'm closing this pull request. I suggest the following fixes could be considered in separate issues, sometime:
|
There is also an option of removing |
Thanks for the contribution anyway, I haven't put much thought in image scale before. |
|
docs for targetSize and contentMode 1346119 |
👍 to all! |
hey @pyrtsa, could you please create a new pull request that would fix rendering errors due to the lack or rounding? Please branch of the |
Change
targetSize
to use the same scale asUIImage.size
. Also useround
(to nearest) to convert scaled dimensions to integer rather than truncating the fractional part.Since sizes in iOS are expressed in logical points, not pixels, it is more natural to treat
targetSize
as logical points, so that decompressing an image ofimage.size == CGSize(width: 400, height: 300)
andimage.scale == 2.0
down totargetSize == CGSize(width: 200, height: 150)
would actually mean the same asdecompressImage(image, 0.5)
– rather thandecompressImage(image, 0.25)
which it did before this patch.