Giter Site home page Giter Site logo

smile4ever4u / blurkit-android Goto Github PK

View Code? Open in Web Editor NEW

This project forked from camerakit/blurkit-android

0.0 2.0 0.0 5.88 MB

The missing Android blurring library. Fast blur-behind layout that parallels iOS.

License: MIT License

Java 100.00%

blurkit-android's Introduction

BlurKit Header

BlurKit is an extraordinarily easy to use utility to get live blurring just like on iOS. Built by Dylan McIntyre.

BlurKit Demo

Perfomance

BlurKit is faster than other blurring libraries due to a number of bitmap retrieval and drawing optimizations. We've been logging benchmarks for the basic high-intensity tasks for a 300dp x 100dp BlurView:

Task BlurKit time Avg. time without BlurKit
Retrieve source bitmap 1-2 ms 8-25 ms
Blur and draw to BlurView 1-2 ms 10-50ms

This results in an average work/frame time of 2-4ms, which will be a seamless experience for most users and apps.

Setup

Add BlurKit to your dependencies block:

compile 'com.wonderkiln:blurkit:1.0.0'

You also need to add RenderScript to your app module. Add these lines to the defaultConfig block of your build.gradle.

renderscriptTargetApi 24
renderscriptSupportModeEnabled true

Usage

BlurLayout

Add a BlurLayout to your layout just like any other view.

<com.wonderkiln.blurkit.BlurLayout
    android:id="@+id/blurLayout"
    android:layout_width="150dp"
    android:layout_height="150dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="BlurKit!"
        android:textColor="@android:color/white" />

</com.wonderkiln.blurkit.BlurLayout>

The layout background will continuously blur the content behind it. If you know your background content will be somewhat static, you can set the layout fps to 0. At any time you can re-blur the background content by calling invalidate() on the BlurLayout.

<com.wonderkiln.blurkit.BlurLayout xmlns:blurkit="http://schemas.android.com/apk/res-auto"
    android:id="@+id/blurLayout"
    android:layout_width="150dp"
    android:layout_height="150dp"
    blurkit:fps="0" />

Other attributes you can configure are the blur radius and the downscale factor. Getting these to work together well can take some experimentation. The downscale factor is a performance optimization; the bitmap for the background content will be downsized by this factor before being drawn and blurred.

<com.wonderkiln.blurkit.BlurLayout xmlns:blurkit="http://schemas.android.com/apk/res-auto"
    android:id="@+id/blurLayout"
    android:layout_width="150dp"
    android:layout_height="150dp"
    blurkit:blurRadius="12"
    blurkit:downscaleFactor="0.12"
    blurkit:fps="60" />

Other

You can use the BlurKit class which has a few useful blurring utilities. Before using this class outside of a BlurLayout, you need to initialize BlurKit.

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        BlurKit.init(this);
    }
}

You can blur a View, or a Bitmap directly.

// View
BlurKit.blur(View src, int radius);

// Bitmap
BlurKit.blur(Bitmap src, int radius);

You can also fastBlur a View. This optimizes the view blurring process by allocating a downsized bitmap and using a Matrix with the bitmaps Canvas to prescale the drawing of the view to the bitmap.

BlurKit.fastBlur(View src, int radius, float downscaleFactor);

To Do (incoming!)

  • SurfaceView support
  • Support for use outside of an Activity (dialogs, etc.)
  • Enhance retrieval of background content to only include views drawn behind the BlurLayout.

Credits

Dylan McIntyre

License

BlurKit-Android is MIT licensed.

blurkit-android's People

Contributors

austinkettner avatar linroid avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.