Android 获取 View 的高斯模糊 Drawable

Android 获取 View 的高斯模糊 Drawable

使用谷歌接口,不兼容 17 以下,需要兼容需处理

object RenderScriptUtil {
    const val RADIUS = 25F //高斯模糊程度 0~25
    /**
     * 获取 View 的高斯模糊 BitmapDrawable
     */
    fun gaussianBlur(v: View): BitmapDrawable {
        val renderScript = RenderScript.create(v.context)
        v.setDrawingCacheEnabled(true)
        val origin = v.getDrawingCache()
        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)
        v.setDrawingCacheEnabled(false)
        return BitmapDrawable(bg)
    }
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值