使用Glide实现毛玻璃的效果

最近项目中需要用到一个接口中获取到的图片作为当前activity的背景图片,并且图片的效果需要是毛玻璃效果。怀着直接使用轮子的心情于是到github上查找轮子,终于找到了。


步骤1.引用库

repositories {
    jcenter()
}

dependencies {
    compile 'jp.wasabeef:glide-transformations:3.0.1'
    // If you want to use the GPU Filters
    compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1'
}
步骤2. 使用Glide转换

Glide.with(this).load(R.drawable.demo)
  .apply(bitmapTransform(new BlurTransformation(25)))
  .into((ImageView) findViewById(R.id.image));
另外值得一提的是还可以进行组合转换如下:
MultiTransformation multi = new MultiTransformation(
    new BlurTransformation(25), 
    new RoundedCornersTransformation(128, 0, RoundedCornersTransformation.CornerType.BOTTOM))))
Glide.with(this).load(R.drawable.demo)
  .apply(bitmapTransform(multi))
  .into((ImageView) findViewById(R.id.image));

 转换可以有各种情况: 

Crop

CropTransformationCropCircleTransformationCropSquareTransformationRoundedCornersTransformation

Color

ColorFilterTransformationGrayscaleTransformation

Blur

BlurTransformation

Mask

MaskTransformation

读者可在github上进行项目查看,链接:https://github.com/wasabeef/glide-transformations


另:如果你使用的是Picasso或Fresco也可以实现相同的效果,同样已有轮子

https://github.com/wasabeef/picasso-transformations
https://github.com/wasabeef/fresco-processors

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值