kolaron icon

Blur image

kolaron | PRO | 01/25/18 01:51:09 PM UTC | 0 ⭐ | 10662 👁️ | Never ⏰ | []
Kotlin |

1.05 KB

|

None

|

0 👍

/

0 👎

build.gradle
 
renderscriptTargetApi 18
renderscriptSupportModeEnabled true
 
//#######################################################################################
 
object BlurBuilder {
 
    private const val BITMAP_SCALE = 0.6f
    private const val BLUR_RADIUS = 15f
 
    fun makeBlur(context: Context, image: Bitmap): Bitmap {
        val width = Math.round(image.width * BITMAP_SCALE)
        val height = Math.round(image.height * BITMAP_SCALE)
 
        val inputBitmap = Bitmap.createScaledBitmap(image, width, height, false)
        val outputBitmap = Bitmap.createBitmap(inputBitmap)
 
        val rs = RenderScript.create(context)
 
        val intrinsicBlur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs))
        val tmpIn = Allocation.createFromBitmap(rs, inputBitmap)
        val tmpOut = Allocation.createFromBitmap(rs, outputBitmap)
 
        intrinsicBlur.setRadius(BLUR_RADIUS)
        intrinsicBlur.setInput(tmpIn)
        intrinsicBlur.forEach(tmpOut)
        tmpOut.copyTo(outputBitmap)
 
        return outputBitmap
    }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎