Android StackBlur is a library that can perform a blurry effect on a Bitmap based on a gradient or radius, and return the result. The library is based on the code of Mario Klingemann.

Overview

Android StackBlur

Android StackBlur is a library that can perform a blurry effect on a Bitmap based on a gradient or radius, and return the result. The library is based on the code of Mario Klingemann.

The library is compatible for Android versions 1.5 (so pretty much compatible with every device).

A library and a sample application are provided with the code.

Example Image Example Image

Acknowledgements

  • Mario Klingemann developed the original algorithm and gave me the idea to port it to Android.
  • Manuel Peinado Gallego has generously pointed me out some other sources working on the same area.
  • Nicolas Pomepuy pointed me out to his really useful article on the topic.
  • Dr-Emann for his contribution adding RenderScript and Muiltithreding support.

Usage

Download the library with git. When it has been imported into your project. First initialize your StackBlurManager to load a sample image:

    stackBlurManager = new StackBlurManager(getBitmapFromAsset(this, "android_platform_256.png"));

Process using a certain radius with the following line:

    stackBlurManager.process(progress*5);

and finally obtain the image and load it into an ImageView or any other component:

    imageView.setImageBitmap(_stackBlurManager.returnBlurredImage() );

If you want to use the native code (NDK), first you need to compile the native files. Move to the folder where you have the project, and call:

    ndk-build

If everything goes alright, you will compile and generate a library object, libblur.so, in the folder libs. For more information regarding the NDK framework, please click here. Then, from the code you just need to code:

    stackBlurManager.processNatively(progress*5);

The function processNatively(int radius) return the image already blurry. This code is 25-30 times faster as the Java code.

If you want to use RenderScript, you can do it by using:

   stackBlurManager.processRenderScript(progress*5);

Version history

  • 10.02.2014: Added Multithreading support thanks to Dr-Emann
  • 27.01.2014: Added Benchmarking, bug fixing thanks to Dr-Emann
  • 10.01.2014: Added RenderScript support thanks to Dr-Emann
  • 04.12.2013: Added support for NDK blurry, much faster.
  • 02.12.2013: Solved the issue #1, provoking an ArrayOutOfBoundsException.
  • 08.09.2013: Added support for Gradle
  • 19.08.2013: Added support for Alpha blurring

Next steps

As soon as I get some free time I want to add the following features:

  • Uploading to MavenCentral
  • Support for PNG9
  • Unit tests

If you want to colaborate with the project, feel free to submit a pull request!

Also, if you have used Android StackBlur on your app and you let me know, I can link it from here :)

Developed By

Enrique López Mañas - [email protected]

Follow me on Twitter Follow me on Google+ Follow me on LinkedIn
Comments
  • Does it work well on SurfaceView?

    Does it work well on SurfaceView?

    SurfaceView is not supported on many libs.They just get a bitmap by activity cutting ,then they blur this bitmap. However it is not work on SurfaceView.Others get blur bitmap by root phone. Google's api can do this,but it need some Athority.

    opened by tangxianqiang 0
  • Robolectric test

    Robolectric test

    I had a problem when I use Robolectric tests. Two of my test use this library but sometimes one of them works and sometimes any works.

    Gradle: compile 'com.commit451:NativeStackBlur:1.0.2'

    Here is my code:

    imageLoader.displayImage(urlImage, imageTitulo, options, new ImageLoadingListener() {
                @Override
                public void onLoadingStarted(String s, View view) {}
                @Override
                public void onLoadingFailed(String s, View view, FailReason failReason) {}
                @Override
                public void onLoadingComplete(String s, View view, Bitmap bitmap) {
                    Bitmap bm = NativeStackBlur.process(bitmap, 10);
                    imageTitulo.setImageBitmap(bm);
                    imageStreetV.setImageBitmap(bitmap);
                }
                @Override
                public void onLoadingCancelled(String s, View view) {}
            });
    

    And here is the output:

    java.lang.NoClassDefFoundError: Could not initialize class com.enrique.stackblur.NativeBlurProcess

    	at com.commit451.nativestackblur.NativeStackBlur.process(NativeStackBlur.java:20)
    	at mx.org.inegi.denuemv.ficha.FichaFragment$6.onLoadingComplete(FichaFragment.java:303)
    	at com.nostra13.universalimageloader.core.ImageLoader.displayImage(ImageLoader.java:253)
    	at com.nostra13.universalimageloader.core.ImageLoader.displayImage(ImageLoader.java:365)
    	at com.nostra13.universalimageloader.core.ImageLoader.displayImage(ImageLoader.java:340)
    	at mx.org.inegi.denuemv.ficha.FichaFragment.setData(FichaFragment.java:296)
    	at mx.org.inegi.denuemv.MapsActivityTest.openFicha(MapsActivityTest.java:153)
    	at mx.org.inegi.denuemv.MapsActivityTest.openStreetViewTest(MapsActivityTest.java:123)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:498)
    	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    	at org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:523)
    	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    	at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:226)
    	at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:108)
    	at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:35)
    	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    	at org.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:62)
    	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:498)
    	at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
    

    The App works as well but the tests failed, I don't know why they failed just sometimes.

    Thanks!

    opened by jxpx91 0
  • ndk-build gives error Check that StackBlur/jni/arm64-v8a/librsjni.so exists  or that its path is corret

    ndk-build gives error Check that StackBlur/jni/arm64-v8a/librsjni.so exists or that its path is corret

    For Faster process of Blur Image I want to use below function

    StackBlurManager stackBlurManager = new StackBlurManager(bitmapFromGalleryOrCamera); stackBlurManager.processNatively(25);

    whenever I use above method .processNatively I am getting following errror java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/packageName-1/base.apk"],nativeLibraryDirectories=[/data/app/[packageName-1/lib/arm, /vendor/lib, /system/lib]]] couldn't find "libblur.so"

    So I have decided that I need to compile StackBlur module with NDK

    but whenever I compile your StackBlur module with ndk-build I am getting following error

    
    Android NDK: WARNING: APP_PLATFORM android-19 is larger than android:minSdkVersion 8 in /..//..//../StackBlur/AndroidManifest.xml    
    Android NDK: ERROR:/..//.../StackBlur/jni/Android.mk:rsjni: LOCAL_SRC_FILES points to a missing file    
    Android NDK: Check that /..//..../StackBlur/jni/arm64-v8a/librsjni.so exists  or that its path is corret
    

    Please suggest me what is the issue? what should I need to do to resolve this

    opened by siddhpuraamitr 1
  • support for Nexus 9

    support for Nexus 9

    When I try to run my app on Nexus 9 with NativeStackBlur dependency, I get the following exception:

    UNCAUGHT EXCEPTION (main). Force logging out.: java.lang.Exception: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/BLA.dev-2/base.apk"],nativeLibraryDirectories=[/data/app/BLA.dev-2/lib/arm64, /vendor/lib64, /system/lib64]]] couldn't find "library.so" ... Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/BLA.dev-2/base.apk"],nativeLibraryDirectories=[/data/app/BLA.dev-2/lib/arm64, /vendor/lib64, /system/lib64]]] couldn't find "library.so" ...

    The app does work on other (non 64-bit) devices.

    opened by roelvandun 0
  • Out Of Memory error

    Out Of Memory error

    Please find the logs.

    E/AndroidRuntime(11680): Caused by: java.lang.OutOfMemoryError: Failed to allocate a 26214412 byte allocation with 13777168 free bytes and 13MB until OOM E/AndroidRuntime(11680): at dalvik.system.VMRuntime.newNonMovableArray(Native Method) E/AndroidRuntime(11680): at android.graphics.Bitmap.nativeCreate(Native Method) E/AndroidRuntime(11680): at android.graphics.Bitmap.createBitmap(Bitmap.java:885) E/AndroidRuntime(11680): at android.graphics.Bitmap.createBitmap(Bitmap.java:909) E/AndroidRuntime(11680): at com.enrique.stackblur.JavaBlurProcess.blur(JavaBlurProcess.java:102) E/AndroidRuntime(11680): at com.enrique.stackblur.StackBlurManager.process(StackBlurManager.java:73) E/AndroidRuntime(11680): at com.micromax.aroundyou.CustomContent$11.doInBackground(CustomContent.java:788) E/AndroidRuntime(11680): at com.micromax.aroundyou.CustomContent$11.doInBackground(CustomContent.java:777) E/AndroidRuntime(11680): at android.os.AsyncTask$2.call(AsyncTask.java:292) E/AndroidRuntime(11680): at java.util.concurrent.FutureTask.run(FutureTask.java:237) E/AndroidRuntime(11680): ... 4 more

    opened by pradeep1806 2
Owner
Enrique López Mañas
I learn, and then do things with what I have learnt.
Enrique López Mañas
[] Easily have blurred and transparent background effect on your Android views.

##[DEPRECATED] BlurBehind Easily have blurred and transparent background effect on your Android views. Before API level 14 there was a Window flag cal

Gokberk Ergun 516 Nov 25, 2022
EtsyBlur is an Android library that allows developers to easily add a glass-like blur effect implemented in the Etsy app.

EtsyBlur EtsyBlur is an Android library that allows developers to easily add a glass-like blur effect implemented in the past Etsy app. Try out the sa

Manabu S. 755 Dec 29, 2022
Library provides an easy way to a add shimmer effect in Android Compose project.

Add a shimmer effect to the layout in Android Compose

Valery 66 Dec 14, 2022
Library project to display DialogFragment with a blur effect.

BlurDialogFragment This project allows to display DialogFragment with a burring effect behind. The blurring part is achieved through FastBlur algorith

tvbarthel 2.1k Dec 29, 2022
ShimmerTextView is a simple library to integrate shimmer effect in your TextView.

ShimmerTextView ShimmerTextView is a simple library to integrate shimmer effect in your TextView. Key features Set a base color in ShimmerTextView. Se

MindInventory 22 Sep 7, 2022
A component for flip animation on Android, which is similar to the effect in Flipboard iPhone/Android

android-flip Aphid FlipView is a UI component to accomplish the flipping animation like Flipboard does. A pre-built demo APK file for Android OS 2.2+

Bo 2.8k Dec 21, 2022
Android ImageViews animated by Ken Burns Effect

KenBurnsView Android library that provides an extension to ImageView that creates an immersive experience by animating its drawable using the Ken Burn

Flávio Faria 2.7k Jan 2, 2023
Android L Ripple effect wrapper for Views

Material Ripple Layout Ripple effect wrapper for Android Views Including in your project compile 'com.balysv:material-ripple:1.0.2' Check for latest v

Balys Valentukevicius 2.3k Dec 29, 2022
Implementation of Ripple effect from Material Design for Android API 9+

RippleEffect ExpandableLayout provides an easy way to create a view called header with an expandable view. Both view are external layout to allow a ma

Robin Chutaux 4.9k Dec 30, 2022
:sparkles: An easy way to implement an elastic touch effect for Android.

ElasticViews ✨ An easy way to implement an elastic touch effect for Android. Including in your project Gradle Add below codes to your root build.gradl

Jaewoong Eum 763 Dec 29, 2022
An easy, flexible way to add a shimmering effect to any view in an Android app.

Shimmer for Android Shimmer is an Android library that provides an easy way to add a shimmer effect to any view in your Android app. It is useful as a

Facebook 5.1k Dec 26, 2022
Memory efficient shimmering effect for Android applications by Supercharge.

DEPRECATED - ShimmerLayout Attention: This tool is now deprecated. Please switch to Shimmer for Android or any other shimmer effect solution. ShimmerL

Supercharge 2.5k Jan 4, 2023
A pager for Android with parallax effect

ParallaxPagerTransformer A pager transformer for Android with parallax effect Installation in your build.gradle file dependencies { // ... com

Javier Gonzalez 654 Dec 29, 2022
"Gooey-Effect" for android-compose

Gooey effect for android-compose "Gooey" is a library made to use "gooey-effect" that exists as a CSS trick in android-compose. Download repositories

SeokHo-Im 5 Oct 12, 2022
ViewAnimator view with a lollipop style reveal effect

ViewRevealAnimator Widget ViewAnimator view with a lollipop style reveal effect. Regular animation can be set (just like the default ViewAnimator) for

Alessandro Crugnola 339 Jun 3, 2022
explosive dust effect for views

ExplosionField explosive dust effect for views Getting started In your build.gradle: dependencies { compile 'tyrantgit:explosionfield:1.0.1' } Ex

null 3.6k Dec 29, 2022
Glass-break effect for views

BrokenView Glass-break effect for views. Demo Download APK Usage Android Studio dependencies { compile 'com.zys:brokenview:1.0.3' } Eclipse Just pu

null 859 Dec 30, 2022
Wave effect of activity animation

WaveCompat Wave effect of activity animation How to use 1. Bind wave touch helper to a view which will start an activity when it clicked: WaveTouchHel

WangJie 348 Nov 29, 2022
Chandrasekar Kuppusamy 799 Nov 14, 2022