/**
* 获取 View 的高斯模糊 Bitmap
*/
fun gaussianBlur(v: View): BitmapDrawable? {
val renderScript = RenderScript.create(v.context)
v.setDrawingCacheEnabled(true)
val origin = v.getDrawingCache() ?: return null
val input = Allocation.createFromBitmap(renderScript, origin)
val output = Allocation.createTyped(renderScript, input.type)
val scriptIntrinsicBlur = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript))
scriptIntrinsicBlur.setRadius(RADIUS)
scriptIntrinsicBlur.setInput(input)
scriptIntrinsicBlur.forEach(output)
output.copyTo(origin)
val bg = Bitmap.createBitmap(origin) ?: return null
v.setDrawingCacheEnabled(false)
return BitmapDrawable(bg)
}
高斯模糊
最新推荐文章于 2022-12-09 15:25:26 发布