tags:

views:

787

answers:

3

Currently in an Android application that I'm developing I'm looping through the pixels of an image to blur it. This takes about 30 seconds on a 640x480 image.

While browsing apps in the Android Market I came across one that includes a blur feature and their blur is very fast (like 5 seconds) so they must be using a different method of blurring.

Anyone know a faster way other than looping through the pixels?

+3  A: 

This is a shot in the dark, but you might try shrinking the image and then enlarging it again. This can be done with Bitmap.createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter). Make sure and set the filter parameter to true. It'll run in native code so it might be faster.

Luke
After some testing and the blurring that I'm doing this actual works well enough for me and it's fast. Thanks!
Greg
If it works good. It's a shame we never got to the bottom of why it was inefficient.
vickirk
You might want to try createScaledBitmap and leaving the image the same size. It is blurring it for me :-(
Casebash
A: 

You could pass the image data through to NDK and do it in C. Should be a bit faster. Out of interest, what algorithm are you using to blur?

tm1rbrt
My slow blur is based on C# code that I had found online: http://www.codeproject.com/KB/GDI-plus/csharpfilters.aspx
Greg
A: 

Hi,
I happened to chance across Surfaces in the Android SDK documentation. There is a Surface Blur which will blur anything behind. You could try placing a Surface over the image and then use the SURFACE_BLUR flag. From the doc:

Creates a Blur surface. Everything behind this surface is blurred by some amount. The quality and refresh speed of the blur effect is not settable or guaranteed. It is an error to lock a Blur surface, since it doesn't have a backing store.

keyboardP