Class BitmapEncoder

  • All Implemented Interfaces:
    Encoder<Resource<android.graphics.Bitmap>>, ResourceEncoder<android.graphics.Bitmap>

    public class BitmapEncoder
    extends java.lang.Object
    implements ResourceEncoder<android.graphics.Bitmap>
    An ResourceEncoder that writes Bitmaps to OutputStreams.

    Bitmaps that return true from ()} are written using Bitmap.CompressFormat.PNG to preserve alpha and all other bitmaps are written using Bitmap.CompressFormat.JPEG.

    See Also:
    Bitmap.compress(android.graphics.Bitmap.CompressFormat, int, java.io.OutputStream)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Option<android.graphics.Bitmap.CompressFormat> COMPRESSION_FORMAT
      An Bitmap.CompressFormat option used as the format to encode the Bitmap.
      static Option<java.lang.Integer> COMPRESSION_QUALITY
      An integer option between 0 and 100 that is used as the compression quality.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean encode​(Resource<android.graphics.Bitmap> resource, java.io.File file, Options options)
      Writes the given data to the given output stream and returns True if the write completed successfully and should be committed.
      EncodeStrategy getEncodeStrategy​(Options options)  
      • Methods inherited from class java.lang.Object

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

      • COMPRESSION_QUALITY

        public static final Option<java.lang.Integer> COMPRESSION_QUALITY
        An integer option between 0 and 100 that is used as the compression quality.

        Defaults to 90.

      • COMPRESSION_FORMAT

        public static final Option<android.graphics.Bitmap.CompressFormat> COMPRESSION_FORMAT
        An Bitmap.CompressFormat option used as the format to encode the Bitmap.

        Defaults to Bitmap.CompressFormat.JPEG for images without alpha and Bitmap.CompressFormat.PNG for images with alpha.

    • Constructor Detail

      • BitmapEncoder

        public BitmapEncoder​(@NonNull
                             ArrayPool arrayPool)
    • Method Detail

      • encode

        public boolean encode​(@NonNull
                              Resource<android.graphics.Bitmap> resource,
                              @NonNull
                              java.io.File file,
                              @NonNull
                              Options options)
        Description copied from interface: Encoder
        Writes the given data to the given output stream and returns True if the write completed successfully and should be committed.
        Specified by:
        encode in interface Encoder<Resource<android.graphics.Bitmap>>
        Parameters:
        resource - The data to write.
        file - The file to write the data to.
        options - The set of options to apply when encoding.