public abstract class DownsampleStrategy extends Object
DownsampleStrategy
does not provide any guarantees about output sizes. Behavior will
differ depending on the 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
Transformation
either instead or in addition to a
DownsampleStrategy
.
Some differences between versions of Android and
ResourceDecoder
s are listed below, but the list is not
comprehensive because DownsampleStrategy
only controls it's output scale value, not
how that output value is used.
Modifier and Type | Class and Description |
---|---|
static class |
DownsampleStrategy.SampleSizeRounding
Indicates whether to prefer to prefer downsampling or scaling to prefer lower memory usage
or higher quality.
|
Modifier and Type | Field and Description |
---|---|
static DownsampleStrategy |
AT_LEAST
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.
|
static DownsampleStrategy |
AT_MOST
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.
|
static DownsampleStrategy |
CENTER_INSIDE
Returns the original image if it is smaller than the target, otherwise it will be downscaled
maintaining its original aspect ratio, so that one of the image's dimensions is exactly equal
to the requested size and the other is less or equal than the requested size.
|
static DownsampleStrategy |
CENTER_OUTSIDE
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.
|
static DownsampleStrategy |
DEFAULT
Default strategy, currently
CENTER_OUTSIDE . |
static DownsampleStrategy |
FIT_CENTER
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.
|
static DownsampleStrategy |
NONE
Performs no downsampling or scaling.
|
static Option<DownsampleStrategy> |
OPTION
Indicates the
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. |
Constructor and Description |
---|
DownsampleStrategy() |
Modifier and Type | Method and Description |
---|---|
abstract DownsampleStrategy.SampleSizeRounding |
getSampleSizeRounding(int sourceWidth,
int sourceHeight,
int requestedWidth,
int requestedHeight)
Returns a non-null
DownsampleStrategy.SampleSizeRounding to use to resolve rounding errors and conflicts
between scaling for the width and the height of the image. |
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 and height when displayed in the requested width and height.
|
public static final DownsampleStrategy FIT_CENTER
This method will upscale if the requested width and height are greater than the source width
and height. To avoid upscaling, use AT_LEAST
, AT_MOST
or
CENTER_INSIDE
.
On pre-KitKat devices, Downsampler
treats this as equivalent to AT_MOST
because only power of two downsampling can be used.
public static final DownsampleStrategy CENTER_OUTSIDE
This method will upscale if the requested width and height are greater than the source width
and height. To avoid upscaling, use AT_LEAST
, AT_MOST
,
or CENTER_INSIDE
.
On pre-KitKat devices, Downsampler
treats this as equivalent to
AT_LEAST
because only power of two downsampling can be used.
public static final DownsampleStrategy AT_LEAST
Does not upscale if the requested dimensions are larger than the original dimensions.
public static final DownsampleStrategy AT_MOST
Does not upscale if the requested dimensions are larger than the original dimensions.
public static final DownsampleStrategy CENTER_INSIDE
Does not upscale if the requested dimensions are larger than the original dimensions.
public static final DownsampleStrategy NONE
public static final DownsampleStrategy DEFAULT
CENTER_OUTSIDE
.public static final Option<DownsampleStrategy> OPTION
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.public abstract float getScaleFactor(int sourceWidth, int sourceHeight, int requestedWidth, int requestedHeight)
The returned scale factor will be split into a power of two sample size applied via
BitmapFactory.Options.inSampleSize
and a float scale factor applied
after downsampling via BitmapFactory.Options.inTargetDensity
and
BitmapFactory.Options.inDensity
. Because of rounding errors the scale
factor may not be applied precisely.
The float scaling factor will only be applied on KitKat+. Prior to KitKat, only the power of two downsampling will be applied.
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.public abstract DownsampleStrategy.SampleSizeRounding getSampleSizeRounding(int sourceWidth, int sourceHeight, int requestedWidth, int requestedHeight)
DownsampleStrategy.SampleSizeRounding
to use to resolve rounding errors and conflicts
between scaling for the width and the height of the image.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.