1、效果图:
2、代码如下
/*** 实现倒影图片显示** @param imgId 目标图片id* @return 倒影图片*/public Bitmap getReflectionPic(int imgId) {//创建资源BitmapBitmap bitmap = BitmapFactory.decodeResource(getResources(), imgId);int width = bitmap.getWidth();int height = bitmap.getHeight();//定义原图与倒影间的间距int spac = 10;//绘制原图的下一半图片Matrix matrix = new Matrix();//倒影翻转matrix.setScale(1, -1);//创建反方向Bitmap,并定义倒影高度Bitmap reflectionPic = Bitmap.createBitmap(bitmap, 0, height / 2, width, height / 2, matrix, false);//合成图片Bitmap benchmarkBitmap = Bitmap.createBitmap(width, height + height / 2 + 60, Bitmap.Config.ARGB_8888);//以合成图片为画布Canvas canvas = new Canvas(benchmarkBitmap);//将原图与倒影图片画在一张图上canvas.drawBitmap(bitmap, 0, 0, null);canvas.drawBitmap(reflectionPic, 0, height + spac, null);//添加遮罩Paint paint = new Paint();//创建线性渐变;color1:渐变色的起始颜色 color2:终止颜色LinearGradient linearGradient = new LinearGradient(0, height + spac, 0,benchmarkBitmap.getHeight(), Color.BLACK, Color.TRANSPARENT, Shader.TileMode.MIRROR);//benchmarkBitmap.getHeight(), Color.BLACK, Color.BLUE, Shader.TileMode.MIRROR);paint.setShader(linearGradient);paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));canvas.drawRect(0, height , width, benchmarkBitmap.getHeight()+ spac, paint);return benchmarkBitmap;}
3、结束。