public final class Downsampler
extends java.lang.Object
BitmapFactory
.Modifier and Type | Class and Description |
---|---|
static interface |
Downsampler.DecodeCallbacks
Callbacks for key points during decodes.
|
Modifier and Type | Field and Description |
---|---|
static Option<java.lang.Boolean> |
ALLOW_HARDWARE_CONFIG
Indicates that it's safe or unsafe to decode
Bitmap s with Bitmap.Config#HARDWARE . |
static Option<DecodeFormat> |
DECODE_FORMAT
Indicates the
DecodeFormat that will be used in conjunction
with the image format to determine the Bitmap.Config to provide to
BitmapFactory.Options.inPreferredConfig when decoding the image. |
static Option<DownsampleStrategy> |
DOWNSAMPLE_STRATEGY
Deprecated.
Use
DownsampleStrategy.OPTION directly instead. |
static Option<java.lang.Boolean> |
FIX_BITMAP_SIZE_TO_REQUESTED_DIMENSIONS
Ensure that the size of the bitmap is fixed to the requested width and height of the resource
from the caller.
|
static Option<PreferredColorSpace> |
PREFERRED_COLOR_SPACE
Sets the
PreferredColorSpace that will be used along with the version of Android and
color space of the requested image to determine the final color space used to decode the image. |
Constructor and Description |
---|
Downsampler(java.util.List<ImageHeaderParser> parsers,
android.util.DisplayMetrics displayMetrics,
BitmapPool bitmapPool,
ArrayPool byteArrayPool) |
Modifier and Type | Method and Description |
---|---|
Resource<android.graphics.Bitmap> |
decode(java.io.InputStream is,
int outWidth,
int outHeight,
Options options)
Returns a Bitmap decoded from the given
InputStream that is rotated to match any EXIF
data present in the stream and that is downsampled according to the given dimensions and any
provided DownsampleStrategy option. |
Resource<android.graphics.Bitmap> |
decode(java.io.InputStream is,
int requestedWidth,
int requestedHeight,
Options options,
Downsampler.DecodeCallbacks callbacks)
Returns a Bitmap decoded from the given
InputStream that is rotated to match any EXIF
data present in the stream and that is downsampled according to the given dimensions and any
provided DownsampleStrategy option. |
Resource<android.graphics.Bitmap> |
decode(android.os.ParcelFileDescriptor parcelFileDescriptor,
int outWidth,
int outHeight,
Options options) |
boolean |
handles(java.nio.ByteBuffer byteBuffer) |
boolean |
handles(java.io.InputStream is) |
boolean |
handles(android.os.ParcelFileDescriptor source) |
public static final Option<DecodeFormat> DECODE_FORMAT
DecodeFormat
that will be used in conjunction
with the image format to determine the Bitmap.Config
to provide to
BitmapFactory.Options.inPreferredConfig
when decoding the image.public static final Option<PreferredColorSpace> PREFERRED_COLOR_SPACE
PreferredColorSpace
that will be used along with the version of Android and
color space of the requested image to determine the final color space used to decode the image.
Refer to PreferredColorSpace
for details on how this option works and its various
limitations.
@Deprecated public static final Option<DownsampleStrategy> DOWNSAMPLE_STRATEGY
DownsampleStrategy.OPTION
directly instead.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 static final Option<java.lang.Boolean> FIX_BITMAP_SIZE_TO_REQUESTED_DIMENSIONS
This can be used as a performance optimization for KitKat and above by fixing the size of the bitmap for a collection of requested resources so that the bitmap pool will not need to allocate new bitmaps for images of different sizes.
public static final Option<java.lang.Boolean> ALLOW_HARDWARE_CONFIG
Bitmap
s with Bitmap.Config#HARDWARE
.
Callers should almost never set this value to true
manually. Glide will already do
so when Glide believes it's safe to do (when no transformations are applied). Instead, callers
can set this value to false
to prevent Glide from decoding hardware bitmaps if Glide is
unable to detect that hardware bitmaps are unsafe. For example, you should set this to false
if you plan to draw it to a software Canvas
or if you plan to
inspect the Bitmap
s pixels with Bitmap.getPixel(int, int)
or Bitmap.getPixels(int[], int, int, int, int, int, int)
.
Callers can disable hardware Bitmap
s for all loads using GlideBuilder.setDefaultRequestOptions(RequestOptions)
.
This option is ignored unless we're on Android O+.
public Downsampler(java.util.List<ImageHeaderParser> parsers, android.util.DisplayMetrics displayMetrics, BitmapPool bitmapPool, ArrayPool byteArrayPool)
public boolean handles(java.io.InputStream is)
public boolean handles(java.nio.ByteBuffer byteBuffer)
public boolean handles(android.os.ParcelFileDescriptor source)
public Resource<android.graphics.Bitmap> decode(java.io.InputStream is, int outWidth, int outHeight, Options options) throws java.io.IOException
InputStream
that is rotated to match any EXIF
data present in the stream and that is downsampled according to the given dimensions and any
provided DownsampleStrategy
option.java.io.IOException
decode(InputStream, int, int, Options, DecodeCallbacks)
public Resource<android.graphics.Bitmap> decode(java.io.InputStream is, int requestedWidth, int requestedHeight, Options options, Downsampler.DecodeCallbacks callbacks) throws java.io.IOException
InputStream
that is rotated to match any EXIF
data present in the stream and that is downsampled according to the given dimensions and any
provided DownsampleStrategy
option.
If a Bitmap is present in the BitmapPool
whose dimensions exactly match those
of the image for the given InputStream is available, the operation is much less expensive in
terms of memory.
is
- An InputStream
to the data for the image.requestedWidth
- The width the final image should be close to.requestedHeight
- The height the final image should be close to.options
- A set of options that may contain one or more supported options that influence
how a Bitmap will be decoded from the given stream.callbacks
- A set of callbacks allowing callers to optionally respond to various
significant events during the decode process.java.io.IOException