Skip to content

Instantly share code, notes, and snippets.

@ruthwikkk
Created October 7, 2023 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruthwikkk/7aab3845f475a8ade33bb05622a7971a to your computer and use it in GitHub Desktop.
Save ruthwikkk/7aab3845f475a8ade33bb05622a7971a to your computer and use it in GitHub Desktop.
Code for RenderScript blur
private fun blurWithRenderScript() {
val renderScript = RenderScript.create(context)
val blurScript = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript))
val inAllocation = Allocation.createFromBitmap(renderScript, bitmap)
val outAllocation = Allocation.createTyped(renderScript, inAllocation.type)
blurScript.setRadius(20f)
blurScript.setInput(inAllocation)
blurScript.forEach(outAllocation)
outAllocation.copyTo(bitmap)
inAllocation.destroy()
}
fun getBackgroundAndDrawBehind(parent: ViewGroup) {
...
...
canvas?.restore()
if (::bitmap.isInitialized) { //Only execute after bitmap is initialized
blurWithRenderScript()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment