Package 

Class DownsampleStrategy


  • 
    public abstract class DownsampleStrategy
    
                        

    Indicates the algorithm to use when downsampling images.

    {@code DownsampleStrategy} does not provide any guarantees about output sizes. Behavior will differ depending on the com.mobwith.imgmodule.load.ResourceDecoder using the strategy and the version of Android the code runs on. Use {@code DownsampleStrategy} as an optimization to improve memory efficiency only. If you need a particular size or shape output, use an either instead or in addition to a {@code * DownsampleStrategy}.

    Some differences between versions of Android and s are listed below, but the list is not comprehensive because DownsampleStrategy only controls its output scale value, not how that output value is used.

    On some versions of Android, precise scaling is not possible. In those cases, the strategies can only pick between downsampling to between 1x the requested size and 2x the requested size and between 0.5x the requested size and 1x the requested size because only power of two downsampling is supported. To preserve the potential for a com.mobwith.imgmodule.load.Transformation to scale precisely without a loss in quality, all but AT_MOST will prefer to downsample to between 1x and 2x the requested size.

    • Method Detail

      • getScaleFactor

         abstract float getScaleFactor(int sourceWidth, int sourceHeight, int requestedWidth, int requestedHeight)

        Returns a float (0, +infinity) indicating a scale factor to apply to the source width andheight when displayed in the requested width and height.

        The returned scale factor will be split into a power of two sample size applied via and a float scale factor applied afterdownsampling via inTargetDensity and . Because of rounding errors the scale factormay not be applied precisely.

        The float scaling factor will only be applied on KitKat+. Prior to KitKat, only the power oftwo downsampling will be applied.

        Parameters:
        sourceWidth - The width in pixels of the image to be downsampled.
        sourceHeight - The height in pixels of the image to be downsampled.
        requestedWidth - The width in pixels of the view/target the image will be displayed in.
        requestedHeight - The height in pixels of the view/target the image will be displayed in.
      • getSampleSizeRounding

         abstract DownsampleStrategy.SampleSizeRounding getSampleSizeRounding(int sourceWidth, int sourceHeight, int requestedWidth, int requestedHeight)

        Returns a non-null SampleSizeRounding to use to resolve rounding errors and conflictsbetween scaling for the width and the height of the image.

        Parameters:
        sourceWidth - The width in pixels of the image to be downsampled.
        sourceHeight - The height in pixels of the image to be downsampled.
        requestedWidth - The width in pixels of the view/target the image will be displayed in.
        requestedHeight - The height in pixels of the view/target the image will be displayed in.