Little nifty helper library to apply a blur-effect to a Bitmap. It also lets you overlay the resulting bitmap with a Color, Drawable or Resource.
Note: this is the setup routine for Eclipse/ANT.
- Import
ImageBlurreras a new Android Project or download the latest .jar file from here and add it to your build path. - Add the following lines to your project.properties file (this references the RenderScript support library):
renderscript.target=19
enderscript.support.mode=true
sdk.buildtools=19.0.1*
* Replace this with the most recent version of the build tools
Using ImageBlurrer is straight-forward, just pass it the bitmap you would like to get blurred and you're ready to go.
Explanation of all parameters:
blurRadius: Defines the blur radius to apply to the incoming bitmap. Range between 1f and 25f.sampleSize: Identical to BitmapFactory.inSampleSize. Must be >= 1. Higher values improve blurriness and performance significantly, but may result in an image that is "too washed out".overlayColor: Lets you overlay the resulting image with aColor.ARGBvalues should be used here, such as#80000000for 50% transparent black overlay.overlayResource: Lets you overlay the resulting image with aResourcefrom yourdrawablefolders.overlayDrawable: Lets you overlay the resulting image with aDrawable.overlayOpacity: Sets the opacity of the overlaidResourceorDrawable. Ranges between0ffor fully a transparent or1ffor a fully opaque overlay. Something inbetween is recommended.
Note, that the combination of blurRadius and sampleSize make up for noticeable differences in performance, but as well as quality of the resulting image.
Code example:
/*
* Signature of this method:
* public static Bitmap ImageBlurrer.blurImage(Context context, Bitmap bitmap, float blurRadius, float sampleSize)
*
*/
Bitmap blurredBitmap = ImageBlurrer.blurImage(getApplicationContext(), originalBitmap, 12.5f);
- Possibility to define whether the overlaying
ResourceorDrawableshould be tiled or stretched across the bitmap.