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
ImageBlurrer
as 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
.ARGB
values should be used here, such as#80000000
for 50% transparent black overlay.overlayResource
: Lets you overlay the resulting image with aResource
from yourdrawable
folders.overlayDrawable
: Lets you overlay the resulting image with aDrawable
.overlayOpacity
: Sets the opacity of the overlaidResource
orDrawable
. Ranges between0f
for fully a transparent or1f
for 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
Resource
orDrawable
should be tiled or stretched across the bitmap.