【Android】图片模糊效果,Blur image with glide or picasso
2015-11-26 14:49
513 查看
转载署源(By:KyleCe):http://blog.csdn.net/kyleceshen/article/details/50055847
最近项目不忙,本着不断改进项目的宗旨,想到了改进图片加载效果。
受启发于medium,想给图片加上加载中先显示模糊照片的效果,因缘巧合,在周刊上看到了这个开源项目
作者是扩展了ImageView做了一个BlurImageView,扒了扒源码,发现它是这么做的:
1.在控件中用picasso做了一个低质量图片的请求,然后用这个开源算法得到了一张模糊图
2.模糊图载入成功后,再去请求高质量的图片
这样一来思路就清晰了,但作者设计时并没有按照MVC的框架来做,把请求的事情做到了View层
公司的项目中,我用的是比Picasso效率更高的Glide(见博客中第三条);所以几番探索之下,发现如下可行之法:
转载署源(By:KyleCe):http://blog.csdn.net/kyleceshen/article/details/50055847
最近项目不忙,本着不断改进项目的宗旨,想到了改进图片加载效果。
受启发于medium,想给图片加上加载中先显示模糊照片的效果,因缘巧合,在周刊上看到了这个开源项目
作者是扩展了ImageView做了一个BlurImageView,扒了扒源码,发现它是这么做的:
1.在控件中用picasso做了一个低质量图片的请求,然后用这个开源算法得到了一张模糊图
2.模糊图载入成功后,再去请求高质量的图片
这样一来思路就清晰了,但作者设计时并没有按照MVC的框架来做,把请求的事情做到了View层
公司的项目中,我用的是比Picasso效率更高的Glide(见博客中第三条);所以几番探索之下,发现如下可行之法:
// set default empty bitmap, or the system will use the other cached pictures instead iv.setImageBitmap(defaultWhiteBitmap); // define the full target, use it when the picture is already blurred final Target fullTarget = new SimpleTarget() { @Override public void onResourceReady(Object resource, GlideAnimation glideAnimation) { if (!(resource instanceof Bitmap)) return; Bitmap fullBitmap = (Bitmap) resource; // full image task // do the full image task iv.setImageBitmap(fullBitmap); } }; // the blur target, blur the picture // when the blur is done, set the full target Target blurTarget = new SimpleTarget() { @Override public void onResourceReady(Object resource, GlideAnimation glideAnimation) { if (!(resource instanceof Bitmap)) return; Bitmap bitmap = (Bitmap) resource; // Do bitmap blur here Bitmap blurBitmap = FastBlurUtil.doBlur(bitmap, 8, true); iv.setImageBitmap(blurBitmap); // full image url String fullImageUrl = "http://www.xxxxxxxxxx"; Glide.with(FragmentMoments.this).load(fullImageUrl).asBitmap().into(fullTarget); } }; // blur image setting //blur image url String blurImageUrl = "http://www.xxxxxxxxxx"; Glide.with(FragmentMoments.this).load(blurImageUrl).asBitmap().into(blurTarget);
转载署源(By:KyleCe):http://blog.csdn.net/kyleceshen/article/details/50055847
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories