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. 《Linux命令行与shell脚本编程大全 第3版》Linux命令行---7

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

  2. 查看windows进程,并删除

    1. 通过[任务管理器]可以查看windows进程. 有些进程不在[任务管理器]中. 2. 通过tasklist命令查看进程. 杀掉进程: epmd 进程,在停止.卸载后rabbitmq服务还在. 通 ...

  3. jenkins 管理员账号丢失

    在jenkins 设置权限后,无法登录 参考: 如何修改jenkins配置权限   https://zhidao.baidu.com/question/497256501658876284.html

  4. ASP.NET MVC创建静态页

    1.在MVC下新建一个类:StaticPageHelper public class StaticPageHelper { /// <summary> /// 根据View视图生成静态页面 ...

  5. 10.1综合强化刷题 Day4

    财富(treasure) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK有n个小伙伴.每个小伙伴有一个身高hi. 这个游戏是这样的,LYK生活的环境是以 ...

  6. Python学习笔记——安装

    最近打算使用下GAE,便准备学习一下python.我对python是一窍不通,因此这里将我的学习历程记录下来,方便后续复习. 安装python: 可以从如下地址:http://www.python.o ...

  7. 手把手教你构建 C 语言编译器

    http://lotabout.me/2015/write-a-C-interpreter-1/

  8. 【Java】List转化为数组

    List转化为数组的两种方式: 第一种: List<String> list = new ArrayList<>(); String [] arr = list.toArray ...

  9. 用PHP实现弹出消息提示框

    方法一: echo "<script>alert('提示内容')</script>"; 方法二: echo '<script language=&qu ...

  10. 用Golang写的域名信息搜集工具

    blacksheepwall是一款由Go语言编写的域名信息搜集工具 ,你也可以在你的工具中将它作为一个独立软件包来使用. 下载 blacksheepwall支持跨平台,目前它所支持的系统有window ...