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. uva 1149:Bin Packing(贪心)

    题意:给定N物品的重量,背包容量M,一个背包最多放两个东西.问至少多少个背包. 思路:贪心,最大的和最小的放.如果这样都不行,那最大的一定孤独终生.否则,相伴而行. 代码: #include < ...

  2. pyinstaller打包exe程序各种坑!!!

    pyinstaller打包python成exe可执行程序,各种报错,各种坑,在次记录下 一.pyinstaller打包报错for real_module_name, six_moduleAttribu ...

  3. centos 7 安装git并配置ssh

    一.安装 1.查看是否安装git rpm -qa|grep git 有git加版本号就说明已经安装过了 2.安装git yum install git 3.查看git版本 git version 二. ...

  4. window postgresql 10.4安装

    window installer下载地址:https://www.enterprisedb.com/downloads/postgres-postgresql-downloads 其他版本官网下载地址 ...

  5. hdu 2104(判断互素)

    hide handkerchief Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  6. entity framework6 edmx文件详解

    entity framework中的edmx文件作为代码与数据库沟通的桥梁,作用是至关重要的.如果edmx文件出了问题,ef就基本上没得用了.虽然edmx文件是由ef自动生成的,但是一些特定的操作可能 ...

  7. Codeforces Round #315 (Div. 2)【贪心/重排去掉大于n的元素和替换重复的元素】

    B. Inventory time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  8. 洛谷——P3387 【模板】缩点

    P3387 [模板]缩点 题目背景 缩点+DP 题目描述 给定一个n个点m条边有向图,每个点有一个权值,求一条路径,使路径经过的点权值之和最大.你只需要求出这个权值和. 允许多次经过一条边或者一个点, ...

  9. Ruby on rails初体验(三)

    继体验一和体验二中的内容,此节将体验二中最开始的目标来实现,体验二中已经将部门添加的部分添加到了公司的show页面,剩下的部分是将部门列表也添加到公司的显示页面,整体思路和体验二中相同,但是还是会有点 ...

  10. jcraft--SFTP demo

    import java.awt.Container; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import ...