Glide使用
来源:互联网 发布:project tango 淘宝 编辑:程序博客网 时间:2024/04/29 17:01
1.
compile 'com.github.bumptech.glide:glide:3.7.0'//图形处理框架,可以不加compile 'jp.wasabeef:glide-transformations:2.0.1' // If you want to use the GPU Filters compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.3.0'
2.使用
final ImageView imageview= (ImageView) findViewById(R.id.my_image_view); Glide.with(this).load("http://attach.bbs.miui.com/forum/201502/08/021410qwvwbpdkiasdhwha.jpg")// .asGif() .diskCacheStrategy(DiskCacheStrategy.SOURCE)// .placeholder(R.mipmap.ic_launcher)// .transform(new GlideCircleTransform(MainActivity.this)) .bitmapTransform(new CropCircleTransformation(MainActivity.this))// .transform(new RoundedCornersTransformation(this,30,0, RoundedCornersTransformation.CornerType.ALL)) .into(imageview);
asgif()和不asgif()区别:
asgif()就不可以调用.bitmapTransform 方法。但是有一个transfrom方法。也就是说你加上asgif你就不可以使用上面我提到的那个图形处理框架。而且不加gif也可以显示gif,而且可以用上面的框架圆角显示
3.当然你可以自己写处理图片的逻辑如下:
//这会让图片圆角显示package cn.xinyu.com.myapplication;import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapShader;import android.graphics.Canvas;import android.graphics.Paint;import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;/** * Created by Administrator on 2016/6/2. */public class GlideCircleTransform extends BitmapTransformation { public GlideCircleTransform(Context context) { super(context); } @Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { return circleCrop(pool, toTransform); } private Bitmap circleCrop(BitmapPool pool, Bitmap toTransform) { if (toTransform == null) return null; int size = Math.min(toTransform.getWidth(), toTransform.getHeight()); int x = (toTransform.getWidth() - size) / 2; int y = (toTransform.getHeight() - size) / 2; // TODO this could be acquired from the pool too Bitmap squared = Bitmap.createBitmap(toTransform, x, y, size, size); Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888); if (result == null) { result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(result); Paint paint = new Paint(); paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); paint.setAntiAlias(true); float r = size / 2f; canvas.drawCircle(r, r, r, paint); return result; } @Override public String getId() { return getClass().getName(); }}
然后使用的时候:
Glide.with(this).load("http://attach.bbs.miui.com/forum/201502/08/021410qwvwbpdkiasdhwha.jpg") .transform(new GlideCircleTransform(MainActivity.this))
4.gif加载慢解决方法
.asGif() .diskCacheStrategy(DiskCacheStrategy.SOURCE)
0 0
- 【Glide】使用
- Glide---使用
- Glide使用
- Glide使用
- Glide使用
- Glide使用
- Glide使用
- Glide 使用
- Glide使用
- Glide使用
- Glide使用
- Glide命令,如何使用glide,glide.lock
- Android - Glide的使用
- Android - Glide的使用
- Glide 的基本使用
- Glide使用记录
- Glide使用总结
- glide使用问题
- Qt 获取CPU信息
- linux 常用命令
- 使用Linux命令行测试网速
- cocos2dx的Render Command的肤浅见解
- cvHaarDetectObjects
- Glide使用
- ListView中getChildAt(index)的使用注意事项
- thinkphp发送邮件 图文教程
- Xcode插件管理工具Alcatraz
- #1启动Cubism Modeler 作准备
- error C2533: “A::{ctor}”: 构造函数不能有返回类型
- 查看工程里有多少行java代码(好装逼)
- 10万+条Json数据写入到数据库
- MIT6.828 Lab4 Part A: Multiprocessor Support and Cooperative Multitasking