1. 软件模糊

用软件的方法。利用cpu计算,无sdk版本号要求。

效果图:

关键模糊代码 github链接

原文 链接

译文 链接

演示样例 代码

本文地址 :http://blog.csdn.net/csqingchen/article/details/43817975

2. 使用RenderScript模糊,

ScriptIntrinsicBlur要求android sdk版本号最低17。

google的官方文档链接

具体使用代码例如以下:

    /**
* 通过调用系统高斯模糊api的方法模糊
*
* @param bitmap source bitmap
* @param outBitmap out bitmap
* @param radius 0 < radius <= 25
* @param context context
* @return out bitmap
*/
public static Bitmap blurBitmap(Bitmap bitmap, Bitmap outBitmap, float radius, Context context) {
//Let's create an empty bitmap with the same size of the bitmap we want to blur
//Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); //Instantiate a new Renderscript
RenderScript rs = RenderScript.create(context); //Create an Intrinsic Blur Script using the Renderscript
ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); //Create the Allocations (in/out) with the Renderscript and the in/out bitmaps
Allocation allIn = Allocation.createFromBitmap(rs, bitmap);
Allocation allOut = Allocation.createFromBitmap(rs, outBitmap); //Set the radius of the blur
blurScript.setRadius(radius); //Perform the Renderscript
blurScript.setInput(allIn);
blurScript.forEach(allOut); //Copy the final bitmap created by the out Allocation to the outBitmap
allOut.copyTo(outBitmap); //recycle the original bitmap
// bitmap.recycle(); //After finishing everything, we destroy the Renderscript.
rs.destroy(); return outBitmap;
}

3. bitmap缩放处理

以上两种模糊方法,bitmap尺寸越小,处理的越迅速。特别是方法一。为了达到须要的模糊效果,通常我们须要对源bitmap缩放的处理。缩放代码例如以下:

  /**
* 比例压缩图片
*
* @param sourceBitmap 源bitmap
* @param scaleFactor 大于1。将bitmap缩小
* @return 缩小scaleFactor倍后的bitmap
*/
public static Bitmap compressBitmap(Bitmap sourceBitmap, float scaleFactor) {
Bitmap overlay = Bitmap.createBitmap((int) (sourceBitmap.getWidth() / scaleFactor),
(int) (sourceBitmap.getHeight() / scaleFactor), Config.ARGB_8888);
Canvas canvas = new Canvas(overlay);
canvas.translate(0, 0);
canvas.scale(1 / scaleFactor, 1 / scaleFactor);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(sourceBitmap, 0, 0, paint);
return overlay;
}

4. 改变图片的对照度/明暗度

具体说明见代码凝视,演示样例代码

/**
* 改变图片对照度,达到使图片明暗变化的效果
*
* @param srcBitmap source bitmap
* @param contrast 图片亮度。0:全黑。小于1,比原图暗;1.0f原图;大于1比原图亮
* @return bitmap
*/
public static Bitmap darkBitmap(Bitmap srcBitmap, float contrast) { float offset = (float) 0.0; //picture RGB offset int imgHeight, imgWidth;
imgHeight = srcBitmap.getHeight();
imgWidth = srcBitmap.getWidth(); Bitmap bmp = Bitmap.createBitmap(imgWidth, imgHeight, Config.ARGB_8888);
ColorMatrix cMatrix = new ColorMatrix();
cMatrix.set(new float[]{contrast, 0, 0, 0, offset,
0, contrast, 0, 0, offset,
0, 0, contrast, 0, offset,
0, 0, 0, 1, 0}); Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(cMatrix)); Canvas canvas = new Canvas(bmp);
canvas.drawBitmap(srcBitmap, 0, 0, paint); return bmp;
}

Android模糊效果总结的更多相关文章

  1. Android 模糊效果

    (1)FastBlur http://www.cnblogs.com/CharlesGrant/p/4813735.html (2)StackBlur 基于RenderScript,StackBlur ...

  2. Android 模糊效果 FastBlur

    import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; impor ...

  3. Android开发——高斯模糊效果的简单实现

    0. 前言 在Android开发中,经常在音乐软件中看到高斯模糊效果. 在找遍了所有高斯模糊的算法代码后,发现stackblur的Java实现是最快的.效果如下所示. 1.  高斯模糊效果实现 Bit ...

  4. Android 高仿微信语音聊天页面高斯模糊效果

    目前的应用市场上,使用毛玻璃效果的APP随处可见,比如用过微信语音聊天的人可以发现,语音聊天页面就使用了高斯模糊效果. 先看下效果图: 仔细观察上图,我们可以发现,背景图以用户头像为模板,对其进行了高 ...

  5. android图片特效处理之模糊效果

    这篇将讲到图片特效处理的模糊效果.跟前面一样是对像素点进行处理,算法是通用的,但耗时会更长,至于为什么,看了下面的代码你就会明白. 算法: 一.简单算法:将像素点周围八个点包括自身一共九个点的RGB值 ...

  6. Android项目实战(五十七):Glide 高斯模糊效果

    核心需要高斯模糊的库 compile 'jp.wasabeef:glide-transformations:2.0.1' 针对于3.7的版本 使用方法为: //加载背景, Glide.with(Mus ...

  7. android 图片特效处理之模糊效果

    这篇将讲到图片特效处理的模糊效果.跟前面一样是对像素点进行处理,算法是通用的,但耗时会更长,至于为什么,看了下面的代码你就会明白. 算法: 一.简单算法:将像素点周围八个点包括自身一共九个点的RGB值 ...

  8. xamarin.android 图片高斯模糊效果

    代码如下: private static float BITMAP_SCALE = 0.1f; private static float BLUR_RADIUS = 12.0f; public sta ...

  9. Android开发学习之路-3DTouch效果模仿

    3D Touch是什么效果的大家应该都知道了.什么?不知道,那也没办法呀,我也没有iPhone 6s演示给你看的. 本篇博客要做的效果图: 来个低质量动图: 这个动图效果不是很好,实际上模糊效果应该是 ...

随机推荐

  1. VS Code开发技巧集锦【转】

    转自:http://blog.csdn.net/tiantangyouzui/article/details/52163175 入门 自定义 扩展 文件/文件夹管理 编辑技巧 智能感应功能 代码片段 ...

  2. 《Linux命令行与shell脚本编程大全 第3版》Linux命令行---15

    以下为阅读<Linux命令行与shell脚本编程大全 第3版>的读书笔记,为了方便记录,特地与书的内容保持同步,特意做成一节一次随笔,特记录如下:

  3. locust参数关联及批量注册

    前言 前面[Locust性能测试2-先登录场景案例]讲了登录的案例,这种是直接传账号和密码就能登录了,有些登录的网站会复杂一点,需要先从页面上动态获取参数,作为登录接口的请求参数,如[学信网:http ...

  4. 解决Spring在线程中注入为空指针的问题

    在启用线程中使用来jdbcTemplate来查询数据库,引入jdbcTemplate是用Spring  @Autowired注解  方式引入,但是在运行中 jdbcTemplate 总是 空指针 解决 ...

  5. Android 代码里设置ImageView的src和background

    设置ImageView的src: image.setImageDrawable(getResources().getDrawable(R.drawable.blackk)); String path= ...

  6. Codeforces 899 A.Splitting in Teams

      A. Splitting in Teams   time limit per test 1 second memory limit per test 256 megabytes input sta ...

  7. iOS 动画笔记 (一)

    你也肯定喜欢炫酷的动画! 在APP中,动画就是一个点睛之笔!可以给用户增加一些独特的体验感,估计也有许多的和我一样的,看着那些觉得不错的动画,也就只能流口水的孩子,毕竟可能不知道从哪里下手去写!动画学 ...

  8. 一款不错的编程字体Source Code Pro

    我以前一直是用的MS自家的是Consolas的字体,这个字体基本上具有编程字体所需的所有要素:等宽.支持ClearType.中文字体大小合适,l和1,o和0很容易区分.非要挑刺的话就是字体比较小,9号 ...

  9. SecureCRT介绍、安装、使用(转)

    http://blog.csdn.net/liang19890820/article/details/49701429 简介 SecureCRT是一款支持SSH(SSH1和SSH2)的终端仿真程序,简 ...

  10. vs2013载入zlib库,即include "zlib.h"

    转自wo13142yanyouxin原文vs2013载入zlib库,即include "zlib.h" 在程序中,我们经常要用到压缩,解压函数.以压缩函数compress为例进行说 ...