Skip to content
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

More precise image resolution #191

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

akexorcist
Copy link

@akexorcist akexorcist commented Oct 14, 2021

Currently, image resize depends on the result of sample size. There's a lot of gap between each sample size value.

For example, resize 3,719 x 2,787 px of original image resolution.

Target Resolution (px)    Result Resolution (px)
------------------------------------------------
400 x 400                 930 x 697
800 x 800                 1,860 x 1,394
1,200 x 1,200             1,860 x 1,394
1,600 x 1,600             3,719 x 2,787
2,000 x 2,000             3,719 x 2,787
2,400 x 2,400             3,719 x 2,787
2,800 x 2,800             3,719 x 2,787
3,200 x 3,200             3,719 x 2,787

You will see a lot of gap for 1,400 x 1,400 px of target resolution because the result of sample size calculation is 1. So it wasn't resized.

For more precise image resize, we have combine the calculation between, inSampleSize, inDensity and inTargetDensity together, not only inSampleSize.

These are results from new calculation

Target Resolution (px)    Result Resolution (px)
------------------------------------------------
400 x 400                 534 x 400
800 x 800                 1,068 x 800
1,200 x 1,200             1,602 x 1,200
1,600 x 1,600             2,135 x 1,600
2,000 x 2,000             2,669 x 2,000
2,400 x 2,400             3,203 x 2,400
2,800 x 2,800             3,719 x 2,787
3,200 x 3,200             3,719 x 2,787

But there is trade-off between current resize calculation compare to my pull request. It is about the execution time.

Target Resolution (px)        Before (ms)        After (ms)         Diff
------------------------------------------------------------------------
400 x 400                     111                71                 -36.03%
800 x 800                     237                134                -43.45%
1,200 x 1,200                 231                218                -5.62%
1,600 x 1,600                 288                363                +26.04%
2,000 x 2,000                 288                500                +73.61%
2,400 x 2,400                 297                644                +116.83%
2,800 x 2,800                 289                288                ~0%
3,200 x 3,200                 289                289                ~0%

If you focus on execution time more than precise resolution, feel free to ignore this pull request or tell me to create it as new constraint.

@akexorcist akexorcist changed the title More precise image resolution resizing More precise image resolution resize Oct 16, 2021
@akexorcist akexorcist changed the title More precise image resolution resize More precise image resolution Oct 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant