Code Monkey home page Code Monkey logo

blur's Introduction

##Blur## [DEPRECATED]此库不再更新,新库地址:https://github.com/robinxdroid/BlurView

高斯模糊库,四种模糊方式

Support

1 Blur 四种模糊方式:RenderScript; Native Pixels; Native Bitmap; Java
2 BlurDrawable 实时模糊Drawable
3 BlurMaskRelativeLayout 模糊底层背景Layout
4.BlurRelativeLayout  模糊当前控件Background

Example

Download demo.apk

Screenshot

Usage

Gradle:

    compile 'net.robinx:lib.blur:1.0.1'

Blur:

blurBitmap = StackBlur.blurJava(willBlurBitmap, blurRadius, false);  //Java方式,缺点:相对于下面三种,速度慢,模糊大图时容易OOM

blurBitmap = StackBlur.blurNatively(willBlurBitmap, blurRadius, false); //Native Bitmap 方式,NDK实现,与Native Pixels方式差距不大

blurBitmap = StackBlur.blurNativelyPixels(willBlurBitmap, blurRadius, false);  //Native Pixels方式 ,NDK实现,推荐使用

blurBitmap = StackBlur.blurRenderScript(context,willBlurBitmap, blurRadius, false); //RenderScript方式,速度极快,约为java方式100倍的速度,NDK方式20倍速度(不同图片质量测试所得结果不同,仅供参考),缺点:API17以上有效,
// radius最大只能设置25,导致模糊的深度不够,不过可以先压缩图片,此问题不是太严重,如果可以忽略API 17的问题,此方式首选

BlurDrawable

扩展Drawable可设置为任何View背景,缺点:实时Blur为了保证FPS使用了RenderScript模糊方式,API 17以上有效

 BlurDrawable blurDrawable = new BlurDrawable(BlurDrawableActivity.this);
                blurDrawable.setDrawOffset(mBlurDrawableRelativeLayout.getLeft(), mBlurDrawableRelativeLayout.getTop() + BlurUtils.getStatusBarHeight(BlurDrawableActivity.this));
                blurDrawable.setCornerRadius(10);
                blurDrawable.setBlurRadius(10);
                blurDrawable.setOverlayColor(Color.parseColor("#64ffffff"));
                mBlurDrawableRelativeLayout.setBackgroundDrawable(blurDrawable);

BlurMaskRelativeLayout

模糊遮罩Layout,可对底层背景进行模糊,此View设置Background无效

1.XML:

 <net.robinx.lib.blur.widget.BlurMaskRelativeLayout
        android:id="@+id/blur_mask_container"
        android:layout_width="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_height="50dp">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="BlurMaskRelativeLayout"
            android:textStyle="bold"
            android:textColor="@android:color/white"
            android:textSize="22sp"/>
    </net.robinx.lib.blur.widget.BlurMaskRelativeLayout>

2.代码中使用:

mBlurMaskRelativeLayout = (BlurMaskRelativeLayout) this.findViewById(R.id.blur_mask_container);
mBlurMaskRelativeLayout.blurMode(BlurMode.RENDER_SCRIPT)
                 .blurRadius(4);

BlurRelativeLayout

对Background进行模糊

    <net.robinx.lib.blur.widget.BlurRelativeLayout
        android:layout_width="match_parent"
        android:background="@mipmap/bg_5"
        android:layout_height="50dp">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="BlurRelativeLayout"
            android:textStyle="bold"
            android:textColor="@android:color/white"
            android:textSize="22sp"/>
    </net.robinx.lib.blur.widget.BlurRelativeLayout>

#About me Email:[email protected]
Blog:www.robinx.net

blur's People

Contributors

robinxdroid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blur's Issues

native方式的速度问题

正常情况下,native的方式是要比renderscript快的;你可以详细看看早就存在的一个项目https://github.com/kikoso/android-stackblur;而这里你说native要比renderscript慢20倍,感觉是你C代码的问题,renderscript其也是编译为本地代码如何能比native快20倍,感觉这里比较蹊跷;当然我没有细看你的源码,只是试了一下;不过效果还是很不错的,点个赞!

页面跳转和计算的时候会出现颜色变化和偏色现象。

底部导航用到此库,
bug1.导航条会出现偏差色彩,正常是白色毛玻璃效果,但是左下角出现了略微的红色。
bug2,跳转Activity,另一个Activity主色调比较暗,返回时候,底部白色毛玻璃也变暗了。
ps:
用的是
main_bottom.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@OverRide
public void onGlobalLayout() {
main_bottom.getViewTreeObserver().removeOnGlobalLayoutListener(this);
BlurDrawable blurDrawable = new BlurDrawable(MainActivity.this);
blurDrawable.setDrawOffset(0, UIUtils.getScreenHeight() - BlurUtils.getStatusBarHeight(MainActivity.this) - UIUtils.dip2px(50));
blurDrawable.setBlurRadius(20);
blurDrawable.setOverlayColor(Color.parseColor("#64ffffff"));
main_bottom.setBackgroundDrawable(blurDrawable);

        }

实时的BlurDrawable

blurDrawable.setDrawOffset(0, UIUtils.getScreenHeight() - BlurUtils.getStatusBarHeight(MainActivity.this) - UIUtils.dip2px(50));

这句代码是解决,我的标题是红色,底部出现红色情况,已经解决。
但是上述问题,依旧无法解决

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.