Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display replica image with mirror image in android [closed]

enter image description here

I want above type of image view in android.

Please suggest me better solutions for implement this.

like image 801
Arvind Kanjariya Avatar asked Nov 30 '12 11:11

Arvind Kanjariya


2 Answers

I use the below code to achieve this effect

public Bitmap applyReflection(Drawable drawable) {
    Bitmap originalImage = ((BitmapDrawable)drawable).getBitmap();
    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);          
    Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height/2), 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, TileMode.CLAMP);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint);

    return bitmapWithReflection;
}

Let me know if you face any issues with the above code.

Credits : http://xjaphx.wordpress.com/learning/tutorials/

like image 185
Royston Pinto Avatar answered Sep 21 '22 01:09

Royston Pinto


Try this :

public static Bitmap reflection(Bitmap mainImage) {
        // gap space between original and reflected
        final int reflectionGap = 4;
        // get image size
        int width = mainImage.getWidth();
        int height = mainImage.getHeight();

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

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

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

        Canvas canvas = new Canvas(reflectedBitmap);
        canvas.drawBitmap(mainImage, 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,
                mainImage.getHeight(), 0, reflectedBitmap.getHeight()
                        + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP);
        paint.setShader(shader);
        paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
        canvas.drawRect(0, height, width, reflectedBitmap.getHeight()
                + reflectionGap, paint);

        return reflectedBitmap;
    }
like image 44
G_S Avatar answered Sep 20 '22 01:09

G_S