Class Downsampler
- java.lang.Object
-
- com.bumptech.glide.load.resource.bitmap.Downsampler
-
public final class Downsampler extends java.lang.ObjectDownsamples, decodes, and rotates images according to their exif orientation usingBitmapFactory.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceDownsampler.DecodeCallbacksCallbacks for key points during decodes.
-
Field Summary
Fields Modifier and Type Field Description static Option<java.lang.Boolean>ALLOW_HARDWARE_CONFIGIndicates that it's safe or unsafe to decodeBitmaps withBitmap.Config.HARDWARE.static Option<DecodeFormat>DECODE_FORMATIndicates theDecodeFormatthat will be used in conjunction with the image format to determine theBitmap.Configto provide toBitmapFactory.Options.inPreferredConfigwhen decoding the image.static Option<DownsampleStrategy>DOWNSAMPLE_STRATEGYDeprecated.UseDownsampleStrategy.OPTIONdirectly instead.static Option<java.lang.Boolean>FIX_BITMAP_SIZE_TO_REQUESTED_DIMENSIONSEnsure 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_SPACESets thePreferredColorSpacethat 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 Summary
Constructors Constructor Description Downsampler(java.util.List<ImageHeaderParser> parsers, android.util.DisplayMetrics displayMetrics, BitmapPool bitmapPool, ArrayPool byteArrayPool)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Resource<android.graphics.Bitmap>decode(android.os.ParcelFileDescriptor parcelFileDescriptor, int outWidth, int outHeight, Options options)Resource<android.graphics.Bitmap>decode(java.io.InputStream is, int outWidth, int outHeight, Options options)Returns a Bitmap decoded from the givenInputStreamthat is rotated to match any EXIF data present in the stream and that is downsampled according to the given dimensions and any providedDownsampleStrategyoption.Resource<android.graphics.Bitmap>decode(java.io.InputStream is, int requestedWidth, int requestedHeight, Options options, Downsampler.DecodeCallbacks callbacks)Returns a Bitmap decoded from the givenInputStreamthat is rotated to match any EXIF data present in the stream and that is downsampled according to the given dimensions and any providedDownsampleStrategyoption.Resource<android.graphics.Bitmap>decode(java.nio.ByteBuffer buffer, int requestedWidth, int requestedHeight, Options options)Identical todecode(InputStream, int, int, Options), except that it accepts aByteBufferin place of anInputStream.booleanhandles(android.os.ParcelFileDescriptor source)booleanhandles(java.io.InputStream is)booleanhandles(java.nio.ByteBuffer byteBuffer)
-
-
-
Field Detail
-
DECODE_FORMAT
public static final Option<DecodeFormat> DECODE_FORMAT
Indicates theDecodeFormatthat will be used in conjunction with the image format to determine theBitmap.Configto provide toBitmapFactory.Options.inPreferredConfigwhen decoding the image.
-
PREFERRED_COLOR_SPACE
public static final Option<PreferredColorSpace> PREFERRED_COLOR_SPACE
Sets thePreferredColorSpacethat 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
PreferredColorSpacefor details on how this option works and its various limitations.
-
DOWNSAMPLE_STRATEGY
@Deprecated public static final Option<DownsampleStrategy> DOWNSAMPLE_STRATEGY
Deprecated.UseDownsampleStrategy.OPTIONdirectly instead.Indicates theDownsampleStrategyoption that will be used to calculate the sample size to use to downsample an image given the original and target dimensions of the image.
-
FIX_BITMAP_SIZE_TO_REQUESTED_DIMENSIONS
public static final 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. The final resource dimensions may differ from the requested width and height, and thus setting this to true may result in the bitmap size differing from the resource 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.
-
ALLOW_HARDWARE_CONFIG
public static final Option<java.lang.Boolean> ALLOW_HARDWARE_CONFIG
Indicates that it's safe or unsafe to decodeBitmaps withBitmap.Config.HARDWARE.Callers should almost never set this value to
truemanually. Glide will already do so when Glide believes it's safe to do (when no transformations are applied). Instead, callers can set this value tofalseto prevent Glide from decoding hardware bitmaps if Glide is unable to detect that hardware bitmaps are unsafe. For example, you should set this tofalseif you plan to draw it to a softwareCanvasor if you plan to inspect theBitmaps pixels withBitmap.getPixel(int, int)orBitmap.getPixels(int[], int, int, int, int, int, int).Callers can disable hardware
Bitmaps for all loads usingGlideBuilder.setDefaultRequestOptions(RequestOptions).This option is ignored unless we're on Android O+.
-
-
Constructor Detail
-
Downsampler
public Downsampler(java.util.List<ImageHeaderParser> parsers, android.util.DisplayMetrics displayMetrics, BitmapPool bitmapPool, ArrayPool byteArrayPool)
-
-
Method Detail
-
handles
public boolean handles(java.io.InputStream is)
-
handles
public boolean handles(java.nio.ByteBuffer byteBuffer)
-
handles
public boolean handles(android.os.ParcelFileDescriptor source)
-
decode
public Resource<android.graphics.Bitmap> decode(java.io.InputStream is, int outWidth, int outHeight, Options options) throws java.io.IOException
Returns a Bitmap decoded from the givenInputStreamthat is rotated to match any EXIF data present in the stream and that is downsampled according to the given dimensions and any providedDownsampleStrategyoption.- Throws:
java.io.IOException- See Also:
decode(InputStream, int, int, Options, DecodeCallbacks)
-
decode
public Resource<android.graphics.Bitmap> decode(java.nio.ByteBuffer buffer, int requestedWidth, int requestedHeight, Options options) throws java.io.IOException
Identical todecode(InputStream, int, int, Options), except that it accepts aByteBufferin place of anInputStream.- Throws:
java.io.IOException
-
decode
public Resource<android.graphics.Bitmap> decode(java.io.InputStream is, int requestedWidth, int requestedHeight, Options options, Downsampler.DecodeCallbacks callbacks) throws java.io.IOException
Returns a Bitmap decoded from the givenInputStreamthat is rotated to match any EXIF data present in the stream and that is downsampled according to the given dimensions and any providedDownsampleStrategyoption.If a Bitmap is present in the
BitmapPoolwhose dimensions exactly match those of the image for the given InputStream is available, the operation is much less expensive in terms of memory.- Parameters:
is- AnInputStreamto 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.- Returns:
- A new bitmap containing the image from the given InputStream, or recycle if recycle is not null.
- Throws:
java.io.IOException
-
-