reflection From Bitmap - Android Graphics

Android examples for Graphics:Canvas

Description

reflection From Bitmap

Demo Code


//package com.java2s;

import android.graphics.Bitmap;

import android.graphics.Canvas;

import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Shader.TileMode;

public class Main {

    public static Bitmap reflectionFromBitmap(Bitmap originalBitmap,
            boolean isFuzzy) {
        int width = originalBitmap.getWidth();
        int height = originalBitmap.getHeight();
        Matrix matrix = new Matrix();
        matrix.preScale(1, -1);//from w  ww  . j  av  a  2s.c  om
        Bitmap reflectionBitmap = Bitmap.createBitmap(originalBitmap, 0, 0,
                width, height, matrix, false);

        if (isFuzzy) {
            Canvas canvasFuzzy = new Canvas(reflectionBitmap);
            Paint paint = new Paint();
            LinearGradient shader = new LinearGradient(0, 0, 0, height,
                    0x80ffffff, 0x00ffffff, TileMode.CLAMP);
            // Set the paint to use this shader (linear gradient)
            paint.setShader(shader);
            // 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
            canvasFuzzy.drawRect(0, 0, width, height, paint);

            return reflectionBitmap;
        }

        return reflectionBitmap;
    }
}

Related Tutorials