效果图
class FilterActivity : AppCompatActivity() {
private val url = "https://c-ssl.duitang.com/uploads/item/201706/05/20170605121955_mkz2y.thumb.700_0.jpeg"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_filter)
loadImage().into(getView("正常"))
loadImage().transform(GrayscaleTransformation())
.into(getView("黑白"))
loadImage()
.transform(GPUFilterTransformation(GPUImageSoftLightBlendFilter()))
.into(getView("暖色"))
loadImage()
.transform(ColorFilterTransformation(0x7900CCCC))
.into(getView("颜色过滤"))
loadImage()
.transform(BlurTransformation(8, 2))
.into(getView("模糊"))
loadImage()
.transform(MaskTransformation(R.mipmap.ic_launcher))
.into(getView("图片遮罩"))
//如下都是GPU过滤(需要依赖GPUImage库)
loadImage().transform(ToonFilterTransformation(0.2f, 10f))
.into(getView("卡通滤波器"))
loadImage().transform(SepiaFilterTransformation(1f))
.into(getView("乌墨色滤波器"))
loadImage().transform(ContrastFilterTransformation(3f))
.into(getView("对比度滤波器"))
loadImage().transform(InvertFilterTransformation())
.into(getView("反转滤波器"))
loadImage().transform(PixelationFilterTransformation(20f))
.into(getView("像素化滤波器"))
loadImage().transform(SketchFilterTransformation())
.into(getView("素描滤波器"))
loadImage().transform(SwirlFilterTransformation(1.0F, 0.4F, PointF(0.5F, 0.5F)))
.into(getView("旋转滤波器"))
loadImage().transform(BrightnessFilterTransformation(0.5f))
.into(getView("亮度滤波器"))
loadImage().transform(KuwaharaFilterTransformation(10))
.into(getView("Kuwahara滤波器"))
loadImage().transform(VignetteFilterTransformation(PointF(0.5F, 0.5F), floatArrayOf(0.0f, 0.0f, 0.0f), 0.0F, 0.5F))
.into(getView("装饰图滤波器"))
}
private fun getView(text: String): ImageView {
var linearLayout = LinearLayout(this)
linearLayout.orientation = LinearLayout.HORIZONTAL
val textView = TextView(this)
textView.text = text
val imageView = ImageView(this)
val layoutParams = LinearLayout.LayoutParams(800, 800)
layoutParams.bottomMargin = 10
linearLayout.addView(textView)
linearLayout.addView(imageView, layoutParams)
rootView.addView(linearLayout)
return imageView
}
private fun loadImage() = Glide.with(this).load(url)
}
完整源代码
https://gitee.com/cxyzy1/glideDemo/blob/master/app/src/main/java/com/cxyzy/glidedemo/FilterActivity.kt
安卓开发入门教程系列汇总 安卓发展历程及前景安卓发展历程 安卓开发前景展望
初探安卓安装开发工具 创建第一个安卓工程
开发语言学习Kotlin语言基础
UI控件学习系列UI控件_TextView UI控件_EditText UI控件_Button UI控件_ImageView UI控件_RadioButton UI控件_CheckBox UI控件_ProgressBar
关注头条号,第一时间获取最新文章: