Android StackBlur

repository·main·Indexed 25 days ago

https://github.com/kikoso/android-stackblur

A library for applying blur effects to Bitmaps using the StackBlur algorithm. It provides multiple implementations via StackBlurManager, including Java (JavaBlurProcess), NDK (C++), and RenderScript to balance visual quality and performance.

Tokens
452
Snippets
1
Records
5
Agent score
36%

What's inside android-stackblur

  1. Use StackBlurManager for Java-based blurring

    main
    To apply a blur effect using standard Java implementation, initialize a StackBlurManager with a Bitmap, call process(int radius) to apply the effect, and then retrieve the result using returnBlurredImage().
  2. Compile and use NDK (Native) blurring

    main

    For significantly faster performance (25-30x faster than Java), you can use the NDK implementation.

    1. Compile the native files: Run ndk-build from your project root. This generates libblur.so in the libs folder.
    2. Use the native method: Call processNatively(int radius) on your StackBlurManager instance.
  3. Blur a Bitmap using JavaBlurProcess

    main
    The JavaBlurProcess class provides a Java-based implementation of the StackBlur algorithm. It serves as a compromise between Gaussian Blur and Box blur, offering better visual quality than Box blur while being significantly faster than Gaussian blur implementations. It uses a multi-threaded approach via StackBlurManager to process the image in horizontal and vertical passes.
  4. blur(Bitmap original, float radius)

    main

    Applies the StackBlur algorithm to the provided Bitmap. The process is split into horizontal and vertical passes and executed across multiple threads using the executor defined in StackBlurManager.

    Parameters:

    • original: The source android.graphics.Bitmap to be blurred.
    • radius: A float representing the blur radius. This value is cast to an int internally.

    Returns:

    • A new android.graphics.Bitmap containing the blurred image in ARGB_8888 configuration.
    • Returns null if the thread execution is interrupted.
    @Override
    public Bitmap blur(Bitmap original, float radius) {
        // ... implementation
    }