Example usage for android.graphics Matrix preScale

List of usage examples for android.graphics Matrix preScale

Introduction

In this page you can find the example usage for android.graphics Matrix preScale.

Prototype

public boolean preScale(float sx, float sy) 

Source Link

Document

Preconcats the matrix with the specified scale.

Usage

From source file:Main.java

public static Bitmap reverseByVertical(Bitmap bitmap) {
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false);
}

From source file:Main.java

public static Bitmap reverseByHorizontal(Bitmap bitmap) {
    Matrix matrix = new Matrix();
    matrix.preScale(-1, 1);
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false);
}

From source file:Main.java

private static Bitmap pictureDrawable2Bitmap(PictureDrawable pictureDrawable) {
    float intrinsicWidth = (float) pictureDrawable.getIntrinsicWidth();
    float intrinsicHeight = (float) pictureDrawable.getIntrinsicHeight();
    float f = 1.0f;
    if (intrinsicWidth < 600.0f || intrinsicHeight < 600.0f) {
        f = Math.min(600.0f / intrinsicWidth, 600.0f / intrinsicHeight);
        intrinsicWidth = (intrinsicWidth * f) + 0.5f;
        intrinsicHeight = (intrinsicHeight * f) + 0.5f;
    }// ww  w  . j a  va2s .  c om
    Bitmap createBitmap = Bitmap.createBitmap((int) intrinsicWidth, (int) intrinsicHeight, Config.ARGB_8888);
    Canvas canvas = new Canvas(createBitmap);
    Matrix matrix = new Matrix();
    matrix.preScale(f, f);
    canvas.concat(matrix);
    canvas.drawPicture(pictureDrawable.getPicture());
    return createBitmap;
}

From source file:Main.java

public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap) {
    int i = bitmap.getWidth();
    int j = bitmap.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1.0F, -1F);
    Bitmap bitmap1 = Bitmap.createBitmap(bitmap, 0, j / 2, i, j / 2, matrix, false);
    Bitmap bitmap2 = Bitmap.createBitmap(i, j + j / 2, android.graphics.Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap2);
    canvas.drawBitmap(bitmap, 0.0F, 0.0F, null);
    Paint paint = new Paint();
    canvas.drawRect(0.0F, j, i, j + 4, paint);
    canvas.drawBitmap(bitmap1, 0.0F, j + 4, null);
    Paint paint1 = new Paint();
    paint1.setShader(new LinearGradient(0.0F, bitmap.getHeight(), 0.0F, 4 + bitmap2.getHeight(), 0x70ffffff,
            0xffffff, android.graphics.Shader.TileMode.CLAMP));
    paint1.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.DST_IN));
    canvas.drawRect(0.0F, j, i, 4 + bitmap2.getHeight(), paint1);
    return bitmap2;
}

From source file:Main.java

public static Bitmap setReflection(Bitmap bitmap, int distance, float ratio) {
    final int reflectionGap = distance;
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionBitmap = Bitmap.createBitmap(bitmap, 0, height / 2, width, (int) (height * ratio), matrix,
            false);/*from  w ww . j  av  a2  s  . c  o m*/
    Bitmap withReflectionBitmap = Bitmap.createBitmap(width, (height + (int) (height * ratio) + reflectionGap),
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(withReflectionBitmap);
    canvas.drawBitmap(bitmap, 0, 0, null);
    Paint defaultPaint = new Paint();
    defaultPaint.setColor(Color.TRANSPARENT);
    canvas.drawRect(0, height, width, height + reflectionGap, defaultPaint);
    canvas.drawBitmap(reflectionBitmap, 0, height + reflectionGap, null);

    Paint paint = new Paint();
    LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0, withReflectionBitmap.getHeight(),
            0x70ffffff, 0x00ffffff, Shader.TileMode.MIRROR);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));

    canvas.drawRect(0, height, width, withReflectionBitmap.getHeight(), paint);
    return withReflectionBitmap;
}

From source file:Main.java

public static Bitmap applyReflection(Bitmap originalImage) {
    final int reflectionGap = 4;
    int width = originalImage.getWidth();
    int height = originalImage.getHeight();

    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);

    Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height / 2, width, height / 2, matrix,
            false);//from w w w .j a v  a2  s .co  m

    Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmapWithReflection);
    canvas.drawBitmap(originalImage, 0, 0, null);
    Paint defaultPaint = new Paint();
    canvas.drawRect(0, height, width, height + reflectionGap, defaultPaint);
    canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);

    Paint paint = new Paint();
    LinearGradient shader = new LinearGradient(0, originalImage.getHeight(), 0,
            bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, Shader.TileMode.CLAMP);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint);

    return bitmapWithReflection;
}

From source file:Main.java

public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap) {
    final int reflectionGap = 4;
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);

    Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height / 2, width, height / 2, matrix, false);

    Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmapWithReflection);
    canvas.drawBitmap(bitmap, 0, 0, null);
    Paint deafalutPaint = new Paint();
    canvas.drawRect(0, height, width, height + reflectionGap, deafalutPaint);

    canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);

    Paint paint = new Paint();
    LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0,
            bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP);
    paint.setShader(shader);/*from   w w  w  . j  a  va  2  s . c o m*/
    // Set the Transfer mode to be porter duff and destination in   
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    // Draw a rectangle using the paint with our linear gradient   
    canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint);

    return bitmapWithReflection;
}

From source file:Main.java

public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap) {
    final int reflectionGap = 4;
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, h / 2, w, h / 2, matrix, false);
    Bitmap bitmapWithReflection = Bitmap.createBitmap(w, (h + h / 2), Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmapWithReflection);
    canvas.drawBitmap(bitmap, 0, 0, null);
    Paint deafalutPaint = new Paint();
    canvas.drawRect(0, h, w, h + reflectionGap, deafalutPaint);
    canvas.drawBitmap(reflectionImage, 0, h + reflectionGap, null);
    Paint paint = new Paint();
    LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0,
            bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP);
    paint.setShader(shader);/*from   w w  w.  j av  a 2 s . c o  m*/
    // Set the Transfer mode to be porter duff and destination in
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    // Draw a rectangle using the paint with our linear gradient
    canvas.drawRect(0, h, w, bitmapWithReflection.getHeight() + reflectionGap, paint);
    return bitmapWithReflection;
}

From source file:Main.java

public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap) {
    final int reflectionGap = 4;
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);

    Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height / 2, width, height / 2, matrix, false);

    Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmapWithReflection);
    canvas.drawBitmap(bitmap, 0, 0, null);
    Paint deafalutPaint = new Paint();
    canvas.drawRect(0, height, width, height + reflectionGap, deafalutPaint);

    canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);

    Paint paint = new Paint();
    LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0,
            bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, Shader.TileMode.CLAMP);
    paint.setShader(shader);/*from   w  w  w  .  j  a v  a2s. c om*/
    // Set the Transfer mode to be porter duff and destination in
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    // Draw a rectangle using the paint with our linear gradient
    canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint);

    return bitmapWithReflection;
}

From source file:Main.java

public static Bitmap getReflectionImageWithOrigin(Bitmap bitmap) {
    final int reflectionGap = 4;
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);

    Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height / 2, width, height / 2, matrix, false);

    Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmapWithReflection);
    canvas.drawBitmap(bitmap, 0, 0, null);
    Paint deafalutPaint = new Paint();
    canvas.drawRect(0, height, width, height + reflectionGap, deafalutPaint);

    canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);

    Paint paint = new Paint();
    LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0,
            bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP);
    paint.setShader(shader);//from   w w w  .j av  a  2 s.  c  o  m
    // Set the Transfer mode to be porter duff and destination in
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    // Draw a rectangle using the paint with our linear gradient
    canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint);

    return bitmapWithReflection;
}