Class Downsampler
BitmapFactory.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCallbacks for key points during decodes. -
Field Summary
FieldsModifier and TypeFieldDescriptionIndicates that it's safe or unsafe to decodeBitmaps withBitmap.Config.HARDWARE.static final Option<DecodeFormat>Indicates theDecodeFormatthat will be used in conjunction with the image format to determine theBitmap.Configto provide toBitmapFactory.Options.inPreferredConfigwhen decoding the image.static final Option<DownsampleStrategy>Deprecated.Ensure that the size of the bitmap is fixed to the requested width and height of the resource from the caller.static final Option<PreferredColorSpace>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. -
Constructor Summary
ConstructorsConstructorDescriptionDownsampler(List<ImageHeaderParser> parsers, DisplayMetrics displayMetrics, BitmapPool bitmapPool, ArrayPool byteArrayPool) -
Method Summary
Modifier and TypeMethodDescriptiondecode(ParcelFileDescriptor parcelFileDescriptor, int outWidth, int outHeight, Options options) decode(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.decode(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.decode(ByteBuffer buffer, int requestedWidth, int requestedHeight, Options options) Identical todecode(InputStream, int, int, Options), except that it accepts aByteBufferin place of anInputStream.booleanhandles(ParcelFileDescriptor source) booleanhandles(InputStream is) booleanhandles(ByteBuffer byteBuffer)
-
Field Details
-
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
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.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
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
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 Details
-
Downsampler
public Downsampler(List<ImageHeaderParser> parsers, DisplayMetrics displayMetrics, BitmapPool bitmapPool, ArrayPool byteArrayPool)
-
-
Method Details
-
handles
-
handles
-
handles
-
decode
public Resource<Bitmap> decode(InputStream is, int outWidth, int outHeight, Options options) throws 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:
IOException- See Also:
-
decode
public Resource<Bitmap> decode(ByteBuffer buffer, int requestedWidth, int requestedHeight, Options options) throws IOException Identical todecode(InputStream, int, int, Options), except that it accepts aByteBufferin place of anInputStream.- Throws:
IOException
-
decode
public Resource<Bitmap> decode(InputStream is, int requestedWidth, int requestedHeight, Options options, Downsampler.DecodeCallbacks callbacks) throws 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:
IOException
-
decode
@RequiresApi(21) public Resource<Bitmap> decode(ParcelFileDescriptor parcelFileDescriptor, int outWidth, int outHeight, Options options) throws IOException - Throws:
IOException
-
DownsampleStrategy.OPTIONdirectly instead.