Code example for Matrix

Methods: createBitmap, preScale

0
 
        // The gap we want between the reflection and the original image 
        final int reflectionGap = 4;
 
        // This will not scale but will flip on the Y axis 
        Matrix matrix = new Matrix();
        matrix.preScale(1, -1);
 
        // Create a Bitmap with the flip matix applied to it. 
        // We only want the bottom half of the image 
        Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height / 2, width, height / 2, matrix, false);
 
        // Create a new bitmap with same width but taller to fit reflection 
        Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Bitmap.Config.ARGB_8888);
 
        // Create a new Canvas with the bitmap that's big enough for 
        // the image plus gap plus reflection 
        Canvas canvas = new Canvas(bitmapWithReflection);
 
        // Draw in the original image 
        canvas.drawBitmap(originalImage, 0, 0, null);