You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code calculates a transformation matrix, which is then passed to Android's Canvas.drawBitmap which does the scaling.
We could create some kind of Scaler interface with a drawScaledBitmapToCanvas method, pull out these lines into an implementation of that interface, and then pass an instance of that interface as an argument to the constructor of SubsamplingScaleImageView. That would be an easy way to allow users to implement their own scaling algorithms. Although all of this runs blocking, so performance may be an issue with more intense scaling algorithms.
*It's possible that the scaling is done earlier, in the decoder, but that doesn't seem to be the case for the general fit-to-screen decoding.
Looking further, the correct place to deal with better scaling algorithms is actually probably the ImageRegionDecoder. The main view uses that class to subsample the images by a power of two factor, and the results are cached between canvas draws.
Now ultimately, the sampled images are still up to 2x the screen resolution, so whether using a fancier algorithm is helpful remains to be seen.
Activity
lord-ne commentedon Aug 5, 2026
Currently, as far as I can tell the scaling is done here*:
subsampling-scale-image-view/library/src/main/java/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java
Lines 1056 to 1069 in 173e421
The code calculates a transformation matrix, which is then passed to Android's
Canvas.drawBitmapwhich does the scaling.We could create some kind of
Scalerinterface with adrawScaledBitmapToCanvasmethod, pull out these lines into an implementation of that interface, and then pass an instance of that interface as an argument to the constructor ofSubsamplingScaleImageView. That would be an easy way to allow users to implement their own scaling algorithms. Although all of this runs blocking, so performance may be an issue with more intense scaling algorithms.*It's possible that the scaling is done earlier, in the decoder, but that doesn't seem to be the case for the general fit-to-screen decoding.
lord-ne commentedon Aug 5, 2026
Looking further, the correct place to deal with better scaling algorithms is actually probably the
ImageRegionDecoder. The main view uses that class to subsample the images by a power of two factor, and the results are cached between canvas draws.Now ultimately, the sampled images are still up to 2x the screen resolution, so whether using a fancier algorithm is helpful remains to be seen.