生成带有透明渐变倒影的图片

//生成带有倒影的图片
public void createReflectedBitmap() {
private int[]
 imageIds = new int[]{ R.drawable.photo1, R.drawable.photo2, R.drawable.photo3, R.drawable.photo4, R.drawable.photo5, R.drawable.photo6, R.drawable.photo7,                  R.drawable.photo8
int ReflectionGap = 4;//原图片于倒影之间的距离
int index = 0;
for(int imageId : imageIds){
//源图片
Bitmap resourceBitmap = BitmapFactory.decodeResource(context.getResources(), imageId);
int width = resourceBitmap.getWidth();
int height = resourceBitmap.getHeight();
//生成倒影图片
//Bitmap source 源图片
//x,y 生成倒影图片的起始位置  左上角
//width,height 图片的宽高
// Matrix m 用来 设置图片的样式 (倒影)
Matrix matrix = new Matrix();
// x水平翻转     y垂直翻转    1 正常     -1翻转
matrix.setScale(1, -1); 
Bitmap refrectionBitmap = Bitmap.createBitmap(resourceBitmap, 0, height/2, width, height/2, matrix, false);
//带有倒影的图片
Bitmap bitmap = Bitmap.createBitmap(width, height + height/2, Config.ARGB_8888);
//创建画布 
Canvas canvas = new Canvas(bitmap);
//绘制源图片
canvas.drawBitmap(resourceBitmap, 0, 0, null);
//绘制   原图片于倒影之间的距离
Paint defaultPaint = new Paint();
canvas.drawRect(0, height, width, height + ReflectionGap, defaultPaint);
//绘制倒影图片
canvas.drawBitmap(refrectionBitmap, 0, height + ReflectionGap, null);
// ps中  渐变  遮罩
Paint paint = new Paint();
//遮罩
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
//渐变
//0x70ffffff, 0x00ffffff
/*
 * //线性渐变填充 shader着色器
//在位图上Y方向花砖模式 
TileMode:(一共有三种) 
CLAMP :如果渲染器超出原始边界范围,会复制范围内边缘染色。 
REPEAT :横向和纵向的重复渲染器图片,平铺。 
MIRROR :横向和纵向的重复渲染器图片,这个和REPEAT 重复方式不一样,他是以镜像方式平铺。
 */
LinearGradient shader = new LinearGradient(0, height, 0, bitmap.getHeight(), 0x70ffffff, 0x00ffffff, TileMode.CLAMP);
//着色器   用来绘制颜色  上色的
paint.setShader(shader);
canvas.drawRect(0, height, width, bitmap.getHeight(), paint);
//加入图片
ImageView imageView = new ImageView(context);
// imageView.setImageBitmap(resourceBitmap);
BitmapDrawable bd = new BitmapDrawable(bitmap);
bd.setAntiAlias(true);//消除图片锯齿效果  平滑
imageView.setImageDrawable(bd);
//设置图片的大小
imageView.setLayoutParams(new GalleryFlow.LayoutParams(160,240));
images[index++] = imageView;
}
}


转自:http://www.apkbus.com/home.php?mod=space&uid=121336&do=blog&id=57992

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值