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
Utility functions to perform dynamic operations on Android.

Dynamic Utils A collection of static methods and packages to perform dynamic operations on Android 2.3 (API 9) and above. Since v0.4.0, it uses 26.x.x

Pranav Pandey 95 Dec 25, 2022
A Tinder-like Android library to create the swipe cards effect. You can swipe left or right to like or dislike the content.

Swipecards Travis master: A Tinder-like cards effect as of August 2014. You can swipe left or right to like or dislike the content. The library create

Dionysis Lorentzos 2.3k Dec 9, 2022
This is a picker view for android , support linkage effect, timepicker and optionspicker.(时间选择器、省市区三级联动)

Android-PickerView English Document 注意事项、详请使用方式、更新日志等,请查看 Wiki文档 Wiki文档,Wiki文档,Wiki文档 !~ 重要的事情说三遍 对于使用上有任何疑问或优化建议等,欢迎加入QQ群讨论交流技术问题。 交流群1: 387051294(推荐

Bigkoo 13.2k Jan 6, 2023
Simple and fantastic wheel view in realistic effect for android.

Overview ![Size](https://img.shields.io/badge/Size-17 KB-e91e63.svg) Contact Preview Demo WheelPicke.APK Include Compile compile 'cn.aigestudio.wheelp

Aige 2.5k Jan 6, 2023
A TagView library for Android. Customize your own & Drag effect.

AndroidTagView An Android TagView library. You can customize awesome TagView by using this library. Screenshots Usage Step 1 Add below dependency in y

lujun 1.7k Dec 29, 2022
View that imitates Ripple Effect on click which was introduced in Android L (for Android 2.3+)

RippleView View that imitates Ripple Effect on click which was introduced in Android L. Usage For a working implementation, Have a look at the Sample

Muthuramakrishnan Viswanathan 1.2k Dec 30, 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 Dec 23, 2022
This is a android custom view , like a scratch card effect!

ScratchView This is a android custom view , like a scratch card effect! Last Update 采纳DearZack童鞋的优化思路,把计算擦除面积比例的操作放在手指离开屏幕时,以降低对CPU的占用。 Articles Scrat

D_clock爱吃葱花 316 Nov 29, 2022
JetCompose - Blur Effect in Android 12 with motion layout carousel

JetCompose Blur Effect in Android 12 with motion layout carousel

Vikas Singh 4 Jul 27, 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 858 Jan 6, 2023
Pop animation with circular dust effect for any view updation

Popview-Android Pop animation with circular dust effect for any view updation Getting Started In your build.gradle dependencies { compile 'rb.popv

R B Krishna 489 Dec 28, 2022
An Index Side Bar With Wave Effect

WaveSideBar You can use WaveSideBar in the contacts page of your application. Refer to AlexLiuSheng/AnimSideBar. Screenshot Include the WaveSideBar to

郭佳哲 1.3k Dec 12, 2022
Squishy button effect with kotlin

Squishy Usage Add squishy() modifier on your composable element. Text( text = "Squishhhhyyyyy", modifier = Modifier .size(200.dp, 100.dp

null 43 Jul 9, 2022
This is a sample Android Studio project that shows the necessary code to create a note list widget, And it's an implementation of a lesson on the Pluralsight platform, but with some code improvements

NoteKeeper-Custom-Widgets This is a sample Android Studio project that shows the necessary code to create a note list widget, And it's an implementati

Ibrahim Mushtaha 3 Oct 29, 2022
Proof of concept Android WebView implementation based on Chromium code

Deprecation Notice This project is un-maintained. The recommended alternative is the Crosswalk Project. I did not have the time to keep the project up

Victor Costan 1.7k Dec 25, 2022
FogView is a android library that can show fog on any layout and the fog removes when user rubs it.

Fog View Android Library Min SDK 8 (Android 2.2–2.2.3 Froyo) Screnshots How to use If you want use this library, you can download project and import i

Chetan Kaushik 631 Dec 31, 2022
A View on which you can freely draw, customizing paint width, alpha and color, and take a screenshot of the content. Useful for note apps, signatures or free hand writing.

FreeDrawView A View that let you draw freely on it. You can customize paint width, alpha and color. Can be useful for notes app, signatures or hands-f

Riccardo Moro 643 Nov 28, 2022
ExpandableSelector is an Android library created to show a list of Button/ImageButton widgets inside a animated container which can be collapsed or expanded.

ExpandableSelector ExpandableSelector is an Android library created to show a list of Button/ImageButton widgets inside a animated container which can

Karumi 699 Nov 19, 2022
💳 A quick and easy flip view through which you can create views with two sides like credit cards, poker cards etc.

The article on how this library was created is now published. You can read it on this link here. →. ?? EasyFlipView Built with ❤︎ by Wajahat Karim and

Wajahat Karim 1.3k Dec 14, 2022