Class BitmapChanger


  • public final class BitmapChanger
    extends java.lang.Object
    A factory class providing functions to change bitmap.
    • Constructor Summary

      Constructors 
      Constructor Description
      BitmapChanger()
      Instantiate a BitmapChanger for use.
      BitmapChanger​(android.graphics.Bitmap src)
      Create a copy bitmap for change and do not modify the source.
      BitmapChanger​(android.graphics.Bitmap src, boolean recycle)
      Create a copy bitmap for change.
      BitmapChanger​(android.graphics.Bitmap src, int x, int y, int width, int height)
      Copy a bitmap region from the source for change and do not modify the source.
      BitmapChanger​(android.graphics.Bitmap src, android.graphics.Rect region)
      Copy a bitmap region from the source for change and do not modify the source.
      BitmapChanger​(android.graphics.Bitmap src, android.graphics.RectF region)
      Copy a bitmap region from the source for change and do not modify the source.
    • Constructor Detail

      • BitmapChanger

        public BitmapChanger​(@NonNull
                             android.graphics.Bitmap src)
        Create a copy bitmap for change and do not modify the source.
        Parameters:
        src - the source bitmap
        See Also:
        BitmapChanger(android.graphics.Bitmap,boolean)
      • BitmapChanger

        public BitmapChanger​(@NonNull
                             android.graphics.Bitmap src,
                             boolean recycle)
        Create a copy bitmap for change. If @param recycle is false, it will not modify the source, else it will recycle the source bitmap.
        Parameters:
        src - the source bitmap
        recycle - whether recycle source
        See Also:
        BitmapChanger()
      • BitmapChanger

        public BitmapChanger​(@NonNull
                             android.graphics.Bitmap src,
                             @NonNull
                             android.graphics.Rect region)
        Copy a bitmap region from the source for change and do not modify the source.
        Parameters:
        src - the source bitmap
        region - the region
        See Also:
        BitmapChanger(android.graphics.Bitmap,int,int,int,int)
      • BitmapChanger

        public BitmapChanger​(@NonNull
                             android.graphics.Bitmap src,
                             @NonNull
                             android.graphics.RectF region)
        Copy a bitmap region from the source for change and do not modify the source.
        Parameters:
        src - the source bitmap
        region - the region
        See Also:
        BitmapChanger(android.graphics.Bitmap,int,int,int,int)
      • BitmapChanger

        public BitmapChanger​(@NonNull
                             android.graphics.Bitmap src,
                             int x,
                             int y,
                             int width,
                             int height)
        Copy a bitmap region from the source for change and do not modify the source.
        Parameters:
        src - the source bitmap
        x - region left
        y - region top
        width - region width
        height - region height
      • BitmapChanger

        public BitmapChanger()
        Instantiate a BitmapChanger for use. You may wrap a bitmap for change.
    • Method Detail

      • wrap

        public BitmapChanger wrap​(@NonNull
                                  android.graphics.Bitmap src)
        Create a copy bitmap for change and do not modify the source.
        Parameters:
        src - the source bitmap
        Returns:
        BitmapChanger the current instance
        See Also:
        wrap(Bitmap, boolean)
      • wrap

        public BitmapChanger wrap​(@NonNull
                                  android.graphics.Bitmap src,
                                  boolean recycle)
        Create a copy bitmap for change. If @param recycle is false, it will not modify the source, else it will recycle the source bitmap.
        Parameters:
        src - the source bitmap
        recycle - whether recycle source
        Returns:
        BitmapChanger the current instance
      • wrap

        public BitmapChanger wrap​(@NonNull
                                  android.graphics.Bitmap src,
                                  @NonNull
                                  android.graphics.Rect region)
        Copy a bitmap region from the source for change and do not modify the source.
        Parameters:
        src - the source bitmap
        region - the region
        Returns:
        BitmapChanger the current instance
        See Also:
        wrap(Bitmap, int, int, int, int)
      • wrap

        public BitmapChanger wrap​(@NonNull
                                  android.graphics.Bitmap src,
                                  @NonNull
                                  android.graphics.RectF region)
        Copy a bitmap region from the source for change and do not modify the source.
        Parameters:
        src - the source bitmap
        region - the region
        Returns:
        BitmapChanger the current instance
        See Also:
        wrap(Bitmap, int, int, int, int)
      • wrap

        public BitmapChanger wrap​(@NonNull
                                  android.graphics.Bitmap src,
                                  int x,
                                  int y,
                                  int width,
                                  int height)
        Copy a bitmap region from the source for change and do not modify the source.
        Parameters:
        src - the source bitmap
        x - region left
        y - region top
        width - region width
        height - region height
        Returns:
        BitmapChanger the current instance
      • cut

        public BitmapChanger cut​(int x,
                                 int y,
                                 int width,
                                 int height,
                                 boolean outBounds)
        Cut out region of the bitmap.
        Parameters:
        x - region left
        y - region top
        width - region width
        height - region height
        outBounds - whether create bitmap which can larger than the source
        Returns:
        BitmapChanger the current instance
      • cut

        public BitmapChanger cut​(int x,
                                 int y,
                                 int width,
                                 int height)
        Cut out region of the bitmap (can larger than the source).
        Parameters:
        x - region left
        y - region top
        width - region width
        height - region height
        Returns:
        BitmapChanger the current instance
        See Also:
        cut(int, int, int, int, boolean)
      • crop

        public BitmapChanger crop​(int left,
                                  int top,
                                  int right,
                                  int bottom,
                                  boolean outBounds)
        Cut out region of the bitmap.
        Parameters:
        left - region left
        top - region top
        right - region right
        bottom - region bottom
        outBounds - whether create bitmap which can larger than the source
        Returns:
        BitmapChanger the current instance
      • crop

        public BitmapChanger crop​(int left,
                                  int top,
                                  int right,
                                  int bottom)
        Cut out region of the bitmap (can larger than the source).
        Parameters:
        left - region left
        top - region top
        right - region right
        bottom - region bottom
        Returns:
        BitmapChanger the current instance
        See Also:
        cut(int, int, int, int, boolean)
      • crop

        public BitmapChanger crop​(@NonNull
                                  android.graphics.Rect region,
                                  boolean outBounds)
        Cut out region of the bitmap.
        Parameters:
        region - the region
        outBounds - whether create bitmap which can larger than the source
        Returns:
        BitmapChanger the current instance
        See Also:
        crop(int, int, int, int, boolean)
      • crop

        public BitmapChanger crop​(@NonNull
                                  android.graphics.Rect region)
        Cut out region of the bitmap (can larger than the source).
        Parameters:
        region - the region
        Returns:
        BitmapChanger the current instance
        See Also:
        crop(Rect, boolean)
      • crop

        public BitmapChanger crop​(@NonNull
                                  android.graphics.RectF region,
                                  boolean outBounds)
        Cut out region of the bitmap.
        Parameters:
        region - the region
        outBounds - whether create bitmap which can larger than the source
        Returns:
        BitmapChanger the current instance
        See Also:
        crop(int, int, int, int, boolean)
      • crop

        public BitmapChanger crop​(@NonNull
                                  android.graphics.RectF region)
        Cut out region of the bitmap (can larger than the source).
        Parameters:
        region - the region
        Returns:
        BitmapChanger the current instance
        See Also:
        crop(RectF, boolean)
      • clipPath

        public BitmapChanger clipPath​(@NonNull
                                      android.graphics.Path path)
        Clip path on the whole bitmap.
        Parameters:
        path - path to clip
        Returns:
        BitmapChanger the current instance
      • clipOval

        public BitmapChanger clipOval()
        Clip oval on the whole bitmap.
        Returns:
        BitmapChanger the current instance
        See Also:
        clipPath(Path)
      • clipRoundRect

        public BitmapChanger clipRoundRect​(float radiusX,
                                           float radiusY)
        Clip round rect on the whole bitmap.
        Parameters:
        radiusX - radius x
        radiusY - radius y
        Returns:
        BitmapChanger the current instance
        See Also:
        clipPath(Path)
      • clipRoundRect

        public BitmapChanger clipRoundRect​(@NonNull
                                           float[] radii)
        Clip round rect on the whole bitmap.
        Parameters:
        radii - radii
        Returns:
        BitmapChanger the current instance
        See Also:
        clipPath(Path)
      • matrixChange

        public BitmapChanger matrixChange​(@NonNull
                                          android.graphics.Matrix matrix,
                                          boolean filter)
        Use matrix to change the bitmap.
        Parameters:
        matrix - the matrix for change
        filter - whether use filter
        Returns:
        BitmapChanger the current instance
      • matrixChange

        public BitmapChanger matrixChange​(@NonNull
                                          android.graphics.Matrix matrix)
        Use matrix to change the bitmap (do not use filter).
        Parameters:
        matrix - the matrix for change
        Returns:
        BitmapChanger the current instance
        See Also:
        matrixChange(Matrix, boolean)
      • rotateDegrees

        public BitmapChanger rotateDegrees​(float degrees,
                                           boolean filter)
        Rotate the bitmap.
        Parameters:
        degrees - the degrees
        filter - whether use filter
        Returns:
        BitmapChanger the current instance
        See Also:
        matrixChange(Matrix, boolean)
      • rotateDegrees

        public BitmapChanger rotateDegrees​(float degrees)
        Rotate the bitmap (do not use filter).
        Parameters:
        degrees - the degrees
        Returns:
        BitmapChanger the current instance
        See Also:
        rotateDegrees(float, boolean)
      • rotateRadians

        public BitmapChanger rotateRadians​(float radians,
                                           boolean filter)
        Rotate the bitmap.
        Parameters:
        radians - the radians
        filter - whether use filter
        Returns:
        BitmapChanger the current instance
        See Also:
        rotateDegrees(float, boolean)
      • rotateRadians

        public BitmapChanger rotateRadians​(float radians)
        Rotate the bitmap (do not use filter).
        Parameters:
        radians - the radians
        Returns:
        BitmapChanger the current instance
        See Also:
        rotateRadians(float, boolean);
      • flipHorizontally

        public BitmapChanger flipHorizontally()
        Flip the bitmap horizontally.
        Returns:
        BitmapChanger the current instance
        See Also:
        matrixChange(Matrix)
      • skew

        public BitmapChanger skew​(float skewX,
                                  float skewY,
                                  float centerX,
                                  float centerY,
                                  boolean filter)
        Skew the bitmap.
        Parameters:
        skewX - skew x
        skewY - skew y
        centerX - center x
        centerY - center y
        filter - whether use filter
        Returns:
        BitmapChanger the current instance
        See Also:
        matrixChange(Matrix, boolean)
      • skew

        public BitmapChanger skew​(float skewX,
                                  float skewY,
                                  float centerX,
                                  float centerY)
        Skew the bitmap (do not use filter).
        Parameters:
        skewX - skew x
        skewY - skew y
        centerX - center x
        centerY - center y
        Returns:
        BitmapChanger the current instance
        See Also:
        skew(float, float, float, float, boolean)
      • skew

        public BitmapChanger skew​(float skewX,
                                  float skewY,
                                  boolean filter)
        Skew the bitmap.
        Parameters:
        skewX - skew x
        skewY - skew y
        filter - whether use filter
        Returns:
        BitmapChanger the current instance
        See Also:
        matrixChange(Matrix, boolean)
      • skew

        public BitmapChanger skew​(float skewX,
                                  float skewY)
        Skew the bitmap (do not use filter).
        Parameters:
        skewX - skew x
        skewY - skew y
        Returns:
        BitmapChanger the current instance
        See Also:
        skew(float, float, boolean)
      • scale

        public BitmapChanger scale​(float scaleX,
                                   float scaleY,
                                   boolean filter)
        Scale the bitmap.
        Parameters:
        scaleX - x scale
        scaleY - y scale
        filter - whether use filter
        Returns:
        BitmapChanger the current instance
        See Also:
        matrixChange(Matrix, boolean)
      • scale

        public BitmapChanger scale​(float scaleX,
                                   float scaleY)
        Scale the bitmap (do not use filter).
        Parameters:
        scaleX - x scale
        scaleY - y scale
        Returns:
        BitmapChanger the current instance
        See Also:
        scale(float, float, boolean)
      • scale

        public BitmapChanger scale​(float scale,
                                   boolean filter)
        Scale the bitmap.
        Parameters:
        scale - x & y scale
        filter - whether use filter
        Returns:
        BitmapChanger the current instance
        See Also:
        scale(float, float, boolean)
      • scale

        public BitmapChanger scale​(float scale)
        Scale the bitmap (do not use filter).
        Parameters:
        scale - x & y scale
        Returns:
        BitmapChanger the current instance
        See Also:
        scale(float, float)
      • scaleX

        public BitmapChanger scaleX​(float scaleX,
                                    boolean filter)
        Scale the bitmap.
        Parameters:
        scaleX - x scale
        filter - whether use filter
        Returns:
        BitmapChanger the current instance
        See Also:
        scale(float, float, boolean)
      • scaleX

        public BitmapChanger scaleX​(float scaleX)
        Scale the bitmap (do not use filter).
        Parameters:
        scaleX - x scale
        Returns:
        BitmapChanger the current instance
        See Also:
        scale(float, float)
      • scaleY

        public BitmapChanger scaleY​(float scaleY,
                                    boolean filter)
        Scale the bitmap.
        Parameters:
        scaleY - y scale
        filter - whether use filter
        Returns:
        BitmapChanger the current instance
        See Also:
        scale(float, float, boolean)
      • scaleY

        public BitmapChanger scaleY​(float scaleY)
        Scale the bitmap (do not use filter).
        Parameters:
        scaleY - y scale
        Returns:
        BitmapChanger the current instance
        See Also:
        scale(float, float)
      • resize

        public BitmapChanger resize​(int width,
                                    int height,
                                    boolean filter)
        Scale the bitmap.
        Parameters:
        width - scaled width
        height - scaled height
        filter - whether use filter
        Returns:
        BitmapChanger the current instance
      • resize

        public BitmapChanger resize​(int width,
                                    int height)
        Scale the bitmap (do not use filter).
        Parameters:
        width - scaled width
        height - scaled height
        Returns:
        BitmapChanger the current instance
        See Also:
        resize(int, int, boolean)
      • resizeWidth

        public BitmapChanger resizeWidth​(int width,
                                         boolean filter)
        Scale the bitmap.
        Parameters:
        width - scaled width
        filter - whether use filter
        Returns:
        BitmapChanger the current instance
        See Also:
        resize(int, int, boolean)
      • resizeWidth

        public BitmapChanger resizeWidth​(int width)
        Scale the bitmap (do not use filter).
        Parameters:
        width - scaled width
        Returns:
        BitmapChanger the current instance
        See Also:
        resize(int, int)
      • resizeHeight

        public BitmapChanger resizeHeight​(int height,
                                          boolean filter)
        Scale the bitmap.
        Parameters:
        height - scaled height
        filter - whether use filter
        Returns:
        BitmapChanger the current instance
        See Also:
        resize(int, int, boolean)
      • resizeHeight

        public BitmapChanger resizeHeight​(int height)
        Scale the bitmap (do not use filter).
        Parameters:
        height - scaled height
        Returns:
        BitmapChanger the current instance
        See Also:
        resize(int, int)
      • change

        @NonNull
        public android.graphics.Bitmap change()
        Return the changed bitmap.
        Returns:
        bitmap changed bitmap
      • fill

        public BitmapChanger fill​(int x,
                                  int y,
                                  int color)
        Seed filling.
        Unsupported bitmap config:
        Bitmap.Config.HARDWARE
        Bitmap.Config.RGBA_F16
        Parameters:
        x - position x
        y - position y
        color - color to fill
        Returns:
        BitmapChanger the current instance