Class Downsampler


  • public final class Downsampler
    extends java.lang.Object
    Downsamples, decodes, and rotates images according to their exif orientation using BitmapFactory.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  Downsampler.DecodeCallbacks
      Callbacks for key points during decodes.
    • 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 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​(java.nio.ByteBuffer buffer, int requestedWidth, int requestedHeight, Options options)
      Identical to decode(InputStream, int, int, Options), except that it accepts a ByteBuffer in place of an InputStream.
      boolean handles​(android.os.ParcelFileDescriptor source)  
      boolean handles​(java.io.InputStream is)  
      boolean handles​(java.nio.ByteBuffer byteBuffer)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DECODE_FORMAT

        public static final 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.
      • PREFERRED_COLOR_SPACE

        public static final 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.

        Refer to PreferredColorSpace for details on how this option works and its various limitations.

      • 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 decode Bitmaps 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 Bitmaps pixels with Bitmap.getPixel(int, int) or Bitmap.getPixels(int[], int, int, int, int, int, int).

        Callers can disable hardware Bitmaps for all loads using GlideBuilder.setDefaultRequestOptions(RequestOptions).

        This option is ignored unless we're on Android O+.

    • Constructor Detail

    • 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 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.
        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 to decode(InputStream, int, int, Options), except that it accepts a ByteBuffer in place of an InputStream.
        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 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.

        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.

        Parameters:
        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.
        Returns:
        A new bitmap containing the image from the given InputStream, or recycle if recycle is not null.
        Throws:
        java.io.IOException
      • decode

        @RequiresApi(21)
        public Resource<android.graphics.Bitmap> decode​(android.os.ParcelFileDescriptor parcelFileDescriptor,
                                                        int outWidth,
                                                        int outHeight,
                                                        Options options)
                                                 throws java.io.IOException
        Throws:
        java.io.IOException