使用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

你可能感兴趣的:(Android)