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命令行---10

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

  2. linux下轻松修改pdf文件

    前几天使用firefox打印了一个网页,后来查看有很多页面都是评论,对我来说,实在没有什么用处,就想把多余的内容给删除了,后来,终于找到了一个工具:pdf mod非常不错的工具,直接打开文件,选择要删 ...

  3. anaconda 安装

    1. 安装: 参考博客:https://blog.csdn.net/qq_36851515/article/details/82956150 2. 更新包: 更新失败:conda httperror ...

  4. django 模型生成sql(多对多)

    模型如下: class Publisher(models.Model): name = models.CharField(max_length=30) address = models.CharFie ...

  5. angular6安装

    中文 https://www.angular.cn/ 二.下载 1.安装 node.js https://nodejs.org/en/ 2.删除老angular-cli npm uninstall - ...

  6. 搭建 Maven ---基础入门

    这篇随笔从最基础的控制台  搭建maven讲,后面再升入的讲解IDEA搭建Maven. 一,Maven是什么?作用是什么? Maven是一个项目管理工具,它包含了一个项目对象模型 (Project O ...

  7. 你值得关注的几种常见的js设计模式

    前言 潜水了一段时间,今天空闲时间复盘下之前的知识点,聊聊 js 几种常见的设计模式. 掌握 JavaScript 中常见的一些设计模式,对我们书写规范性代码,可维护性代码有很大的帮助. ps:最近在 ...

  8. SecureCRT分屏显示

    [Tab右键]或者[Session Manager右键]->[Send to New Tab Group]

  9. WebStorm添加多个项目到当前工程目录

    File-> Settings -> Directories -> Add Content Root,选择你要加入的Project 点击OK -> Apply -> OK ...

  10. ADO.NET访问Access(文本数据库)数据操作(CRUD)

    1,ADO.NET访问Access(文本数据库)数据操作(CRUD) 2,DatabaseDesign 文本数据库Northwind.mdb 3,/App_Code 3.1,/App_Code/DBC ...