DownsampleStrategy

abstract class DownsampleStrategy

Indicates the algorithm to use when downsampling images.

DownsampleStrategy does not provide any guarantees about output sizes. Behavior will differ depending on the com.bumptech.glide.load.ResourceDecoder using the strategy and the version of Android the code runs on. Use 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 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.bumptech.glide.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.

Types

Link copied to clipboard
enum SampleSizeRounding
Indicates whether to prefer to prefer downsampling or scaling to prefer lower memory usage or higher quality.

Functions

Link copied to clipboard
abstract fun getSampleSizeRounding(    sourceWidth: Int,     sourceHeight: Int,     requestedWidth: Int,     requestedHeight: Int): DownsampleStrategy.SampleSizeRounding
Returns a non-null SampleSizeRounding to use to resolve rounding errors and conflicts between scaling for the width and the height of the image.
Link copied to clipboard
abstract fun getScaleFactor(    sourceWidth: Int,     sourceHeight: Int,     requestedWidth: Int,     requestedHeight: Int): Float
Returns a float (0, +infinity) indicating a scale factor to apply to the source width and height when displayed in the requested width and height.

Properties

Link copied to clipboard
val AT_LEAST: DownsampleStrategy
Downsamples so the image's smallest dimension is between the given dimensions and 2x the given dimensions, with no size restrictions on the image's largest dimension.
Link copied to clipboard
val AT_MOST: DownsampleStrategy
Downsamples so the image's largest dimension is between 1/2 the given dimensions and the given dimensions, with no restrictions on the image's smallest dimension.
Link copied to clipboard
val CENTER_INSIDE: DownsampleStrategy
Identical to FIT_CENTER, but never upscales.
Link copied to clipboard
val CENTER_OUTSIDE: DownsampleStrategy
Scales, maintaining the original aspect ratio, so that one of the image's dimensions is exactly equal to the requested size and the other dimension is greater than or equal to the requested size.
Link copied to clipboard
val DEFAULT: DownsampleStrategy
Default strategy, currently CENTER_OUTSIDE.
Link copied to clipboard
val FIT_CENTER: DownsampleStrategy
Scales, maintaining the original aspect ratio, so that one of the image's dimensions is exactly equal to the requested size and the other dimension is less than or equal to the requested size.
Link copied to clipboard
val NONE: DownsampleStrategy
Performs no downsampling or scaling.
Link copied to clipboard
val OPTION: Option<DownsampleStrategy>
Indicates the com.bumptech.glide.load.resource.bitmap.DownsampleStrategy option that will be used to calculate the sample size to use to downsample an image given the original and target dimensions of the image.