src/main/java/ru/mail/dondokidon/extensions/BitmapCreator.java
/**
     * Copy scaled according ScaleType param source Bitmap in target Bitmap
     *
     * @param source The bitmap which should be scaled
     * @param target The bitmap which will contain scaled source bitmap in result
     * @param scaleType Scale type to decoded bitmap to fit into created bitmap
     *
     * @throws IllegalStateException if the source bitmap's config is {@link Config#HARDWARE},
     * if the target bitmap is not mutable
     */
Copy scaled according ScaleType param source Bitmap in target Bitmap
@param source The bitmap which should be scaled
@param target The bitmap which will contain scaled source bitmap in result
@param scaleType Scale type to decoded bitmap to fit into created bitmap

@throws IllegalStateException if the source bitmap's config is  Config#HARDWARE,
if the target bitmap is not mutable
Copy scaled according ScaleType param source Bitmap in target Bitmap @param source The bitmap which should be scaled @param target The bitmap which will contain scaled source bitmap in result @param scaleType Scale type to decoded bitmap to fit into created bitmap @throws IllegalStateException if the source bitmap ' s config is Config#HARDWARE if the target bitmap is not mutable
public static void copyScaleTyped(@NotNull Bitmap source, @NotNull Bitmap target, @NotNull ScaleType scaleType){
        Canvas SizeCanvas;
        Matrix SizeMatrix;
        int Width = source.getWidth(), Height = source.getHeight();
        int width = target.getWidth(), height = target.getHeight();
        int startX, startY;
        float scaleX, scaleY, scaleResult;
        switch (scaleType){
            case CENTER:
                startY = Height / 2 - height / 2;
                startX = Width / 2 - width / 2;
                copy(source, target, startX, startY, width, height);
                break;
            case CENTER_CROP:
                scaleX = width / (float) Width;
                scaleY = height / (float) Height;
                if (scaleX > scaleY){
                    scaleResult = scaleX;
                    startX = 0;
                    startY = (int)(Height * scaleResult / 2 - height / 2);
                } else {
                    scaleResult = scaleY;
                    startX = (int)(Width * scaleResult / 2 - width / 2);
                    startY = 0;
                }
                SizeCanvas = new Canvas(target);
                SizeMatrix = new Matrix();
                SizeMatrix.setTranslate(-startX, -startY);
                SizeMatrix.preScale(scaleResult, scaleResult);
                SizeCanvas.drawBitmap(source, SizeMatrix, new Paint());
                break;
            case CENTER_INSIDE:
                scaleX = width / (float) Width;
                scaleY = height / (float) Height;
                scaleResult = Math.min(scaleX, scaleY);
                if (scaleX > scaleY){
                    startX = (int)(Width * scaleResult / 2 - width / 2);
                    startY = 0;
                } else {
                    startX = 0;
                    startY = (int)(Height * scaleResult / 2 - height / 2);
                }
                SizeCanvas = new Canvas(target);
                SizeMatrix = new Matrix();
                SizeMatrix.setTranslate(-startX, -startY);
                SizeMatrix.preScale(scaleResult, scaleResult);
                SizeCanvas.drawBitmap(source, SizeMatrix, new Paint());
                break;
        }
    }
public static void copyScaleTyped ( @ NotNull Bitmap source , @ NotNull Bitmap target , @ NotNull ScaleType scaleType ) { Canvas SizeCanvas ; Matrix SizeMatrix ; int Width = source . getWidth ( ) , Height = source . getHeight ( ) ; int width = target . getWidth ( ) , height = target . getHeight ( ) ; int startX , startY ; float scaleX , scaleY , scaleResult ; switch ( scaleType ) { case CENTER : startY = Height / 2 - height / 2 ; startX = Width / 2 - width / 2 ; copy ( source , target , startX , startY , width , height ) ; break ; case CENTER_CROP : scaleX = width / ( float ) Width ; scaleY = height / ( float ) Height ; if ( scaleX > scaleY ) { scaleResult = scaleX ; startX = 0 ; startY = ( int ) ( Height * scaleResult / 2 - height / 2 ) ; } else { scaleResult = scaleY ; startX = ( int ) ( Width * scaleResult / 2 - width / 2 ) ; startY = 0 ; } SizeCanvas = new Canvas ( target ) ; SizeMatrix = new Matrix ( ) ; SizeMatrix . setTranslate ( - startX , - startY ) ; SizeMatrix . preScale ( scaleResult , scaleResult ) ; SizeCanvas . drawBitmap ( source , SizeMatrix , new Paint ( ) ) ; break ; case CENTER_INSIDE : scaleX = width / ( float ) Width ; scaleY = height / ( float ) Height ; scaleResult = Math . min ( scaleX , scaleY ) ; if ( scaleX > scaleY ) { startX = ( int ) ( Width * scaleResult / 2 - width / 2 ) ; startY = 0 ; } else { startX = 0 ; startY = ( int ) ( Height * scaleResult / 2 - height / 2 ) ; } SizeCanvas = new Canvas ( target ) ; SizeMatrix = new Matrix ( ) ; SizeMatrix . setTranslate ( - startX , - startY ) ; SizeMatrix . preScale ( scaleResult , scaleResult ) ; SizeCanvas . drawBitmap ( source , SizeMatrix , new Paint ( ) ) ; break ; } }
Copy scaled according ScaleType param source Bitmap in target Bitmap
 @param source The bitmap which should be scaled
 @param target The bitmap which will contain scaled source bitmap in result
 @param scaleType Scale type to decoded bitmap to fit into created bitmap
Copy scaled according ScaleType param source Bitmap in target Bitmap @param source The bitmap which should be scaled @param target The bitmap which will contain scaled source bitmap in result @param scaleType Scale type to decoded bitmap to fit into created bitmap