先获取倒影,然后把倒影和原照片合成一张图片。里面使用到了bitmap的静态方法createBitmap(),看下官方文档:
- public static Bitmap createBitmap (Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter)
- Since: API Level 1
- Returns an immutable bitmap from subset of the source bitmap, transformed by the optional matrix. It is initialized with the same density as the original bitmap.
- Parameters
- source The bitmap we are subsetting
- x The x coordinate of the first pixel in source
- y The y coordinate of the first pixel in source
- width The number of pixels in each row
- height The number of rows
- m Optional matrix to be applied to the pixels
- filter true if the source should be filtered. Only applies if the matrix contains more than just translation.
- Returns
- A bitmap that represents the specified subset of source
- Throws
- IllegalArgumentException if the x, y, width, height values are outside of the dimensions of the source bitmap.
参数x、y就是开始复制的起点坐标,就是从原图的那个坐标点开始复制,width设置复制的宽度,height设置高度。
因为代码中注释较详细,这里不再多说。
下面这段代码是设置渐变效果:
- /**
- * 参数一:为渐变起初点坐标x位置,
- * 参数二:为y轴位置,
- * 参数三和四:分辨对应渐变终点,
- * 最后参数为平铺方式,
- * 这里设置为镜像Gradient是基于Shader类,所以我们通过Paint的setShader方法来设置这个渐变
- */
- LinearGradient shader = new LinearGradient(0,originalImage.getHeight(), 0,
- bitmapWithReflection.getHeight() + reflectionGap,0x70ffffff, 0x00ffffff, TileMode.MIRROR);
看完倒影,再来看一下偏转,在main.xml文件中:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"
